Skip to content

Commit 60c5aa2

Browse files
authored
MAUI Android Device Tests (#1703)
1 parent 4e64ad2 commit 60c5aa2

File tree

96 files changed

+5381
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5381
-27
lines changed

.github/workflows/device-tests.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Device tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/*
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
submodules: recursive
18+
19+
- name: Setup Environment
20+
uses: ./.github/actions/environment
21+
22+
- name: Build Native Dependencies
23+
uses: ./.github/actions/buildnative
24+
25+
- name: Build Android Test App
26+
run: dotnet build -c Release -f net6.0-android test/Sentry.Maui.Device.TestApp
27+
28+
- name: Upload Android Test App
29+
uses: actions/upload-artifact@v3
30+
with:
31+
name: device-test-android
32+
if-no-files-found: error
33+
path: test/Sentry.Maui.Device.TestApp/bin/Release/net6.0-android/io.sentry.dotnet.maui.device.testapp-Signed.apk
34+
35+
android:
36+
needs: [build]
37+
name: Run Android API-${{ matrix.api-level }} Test
38+
runs-on: macos-latest # MacOS is required for the emulator, per https://github.com/ReactiveCircus/android-emulator-runner/blob/main/README.md
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
api-level: [27,28,29,30,31,32,33]
43+
env:
44+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
45+
DOTNET_NOLOGO: 1
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v3
49+
50+
- name: Download test app artifact
51+
uses: actions/download-artifact@v3
52+
with:
53+
name: device-test-android
54+
path: bin
55+
56+
- name: Install xharness
57+
run: dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*"
58+
59+
- name: Test
60+
timeout-minutes: 30
61+
uses: reactivecircus/android-emulator-runner@b390b0e1166697ae57c242a0a33c29ca9f5ae078
62+
with:
63+
api-level: ${{ matrix.api-level }}
64+
target: ${{ matrix.api-level <= 27 && 'default' || 'google_apis' }}
65+
force-avd-creation: false
66+
ram-size: 2048M
67+
arch: x86_64
68+
disk-size: 4096M
69+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
70+
disable-animations: false
71+
script: xharness android test --output-directory=./test_output --app=bin/io.sentry.dotnet.maui.device.testapp-Signed.apk --package-name=io.sentry.dotnet.maui.device.testapp
72+
73+
- name: Test Report
74+
if: success() || failure()
75+
run: scripts/parse-xunit2-xml.ps1 ./test_output/TestResults.xml | Out-File $env:GITHUB_STEP_SUMMARY
76+
shell: pwsh
77+
78+
- name: Upload results
79+
if: success() || failure()
80+
uses: actions/upload-artifact@v3
81+
with:
82+
name: device-test-android-${{ matrix.api-level }}-results
83+
path: test_output

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ docs/docfx.zip
2121
/samples/Sentry.Samples.Aws.Lambda.AspNetCoreServer/Properties/launchSettings.json
2222
*.received.*
2323
mono_crash.*.json
24+
test_output/

Sentry.sln

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Maui", "src\Sentry.M
145145
EndProject
146146
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Maui.Tests", "test\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj", "{143076C0-8D6B-4054-9F45-06B21655F417}"
147147
EndProject
148+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sentry.Maui.Device.TestApp", "test\Sentry.Maui.Device.TestApp\Sentry.Maui.Device.TestApp.csproj", "{74221000-29E8-45E6-80D1-977862A3702C}"
149+
EndProject
150+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtils.DeviceTests", "test\MauiTestUtils\DeviceTests\TestUtils.DeviceTests.csproj", "{9FCD773C-3309-482F-A63F-C95B2FFFCDD6}"
151+
EndProject
152+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtils.DeviceTests.Runners.SourceGen", "test\MauiTestUtils\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj", "{CCF39E27-1318-4912-B684-91927592ABB9}"
153+
EndProject
154+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUtils.DeviceTests.Runners", "test\MauiTestUtils\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj", "{6E3BB0B6-3792-47E5-95FB-B410C788507F}"
155+
EndProject
156+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MauiTestUtils", "MauiTestUtils", "{3945EBC3-DDF3-4EBB-9401-B3027E87F855}"
157+
EndProject
148158
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Samples.Ios", "samples\Sentry.Samples.Ios\Sentry.Samples.Ios.csproj", "{C2876321-A612-4E66-AF33-D3928FA6366F}"
149159
EndProject
150160
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sentry.Testing.CrashableApp", "test\Sentry.Testing.CrashableApp\Sentry.Testing.CrashableApp.csproj", "{DA3CECBB-83BE-441A-852C-077809C48307}"
@@ -343,6 +353,24 @@ Global
343353
{143076C0-8D6B-4054-9F45-06B21655F417}.Debug|Any CPU.Build.0 = Debug|Any CPU
344354
{143076C0-8D6B-4054-9F45-06B21655F417}.Release|Any CPU.ActiveCfg = Release|Any CPU
345355
{143076C0-8D6B-4054-9F45-06B21655F417}.Release|Any CPU.Build.0 = Release|Any CPU
356+
{74221000-29E8-45E6-80D1-977862A3702C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
357+
{74221000-29E8-45E6-80D1-977862A3702C}.Debug|Any CPU.Build.0 = Debug|Any CPU
358+
{74221000-29E8-45E6-80D1-977862A3702C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
359+
{74221000-29E8-45E6-80D1-977862A3702C}.Release|Any CPU.ActiveCfg = Release|Any CPU
360+
{74221000-29E8-45E6-80D1-977862A3702C}.Release|Any CPU.Build.0 = Release|Any CPU
361+
{74221000-29E8-45E6-80D1-977862A3702C}.Release|Any CPU.Deploy.0 = Release|Any CPU
362+
{9FCD773C-3309-482F-A63F-C95B2FFFCDD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
363+
{9FCD773C-3309-482F-A63F-C95B2FFFCDD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
364+
{9FCD773C-3309-482F-A63F-C95B2FFFCDD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
365+
{9FCD773C-3309-482F-A63F-C95B2FFFCDD6}.Release|Any CPU.Build.0 = Release|Any CPU
366+
{CCF39E27-1318-4912-B684-91927592ABB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
367+
{CCF39E27-1318-4912-B684-91927592ABB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
368+
{CCF39E27-1318-4912-B684-91927592ABB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
369+
{CCF39E27-1318-4912-B684-91927592ABB9}.Release|Any CPU.Build.0 = Release|Any CPU
370+
{6E3BB0B6-3792-47E5-95FB-B410C788507F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
371+
{6E3BB0B6-3792-47E5-95FB-B410C788507F}.Debug|Any CPU.Build.0 = Debug|Any CPU
372+
{6E3BB0B6-3792-47E5-95FB-B410C788507F}.Release|Any CPU.ActiveCfg = Release|Any CPU
373+
{6E3BB0B6-3792-47E5-95FB-B410C788507F}.Release|Any CPU.Build.0 = Release|Any CPU
346374
{C2876321-A612-4E66-AF33-D3928FA6366F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
347375
{C2876321-A612-4E66-AF33-D3928FA6366F}.Debug|Any CPU.Build.0 = Debug|Any CPU
348376
{C2876321-A612-4E66-AF33-D3928FA6366F}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
@@ -415,6 +443,11 @@ Global
415443
{EBCCABF9-F670-4C8D-AABC-4EB132961929} = {77454495-55EE-4B40-A089-71B9E8F82E89}
416444
{FFFC74C5-680B-43E3-9C42-A7A23B589CB6} = {AF6AF4C7-8AA2-4D59-8064-2D79560904EB}
417445
{143076C0-8D6B-4054-9F45-06B21655F417} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
446+
{74221000-29E8-45E6-80D1-977862A3702C} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
447+
{9FCD773C-3309-482F-A63F-C95B2FFFCDD6} = {3945EBC3-DDF3-4EBB-9401-B3027E87F855}
448+
{CCF39E27-1318-4912-B684-91927592ABB9} = {3945EBC3-DDF3-4EBB-9401-B3027E87F855}
449+
{6E3BB0B6-3792-47E5-95FB-B410C788507F} = {3945EBC3-DDF3-4EBB-9401-B3027E87F855}
450+
{3945EBC3-DDF3-4EBB-9401-B3027E87F855} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
418451
{C2876321-A612-4E66-AF33-D3928FA6366F} = {77454495-55EE-4B40-A089-71B9E8F82E89}
419452
{DA3CECBB-83BE-441A-852C-077809C48307} = {83263231-1A2A-4733-B759-EEFF14E8C5D5}
420453
{3506539B-983C-44FD-BD95-1931562E7919} = {77454495-55EE-4B40-A089-71B9E8F82E89}

SentryMaui.slnf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
1010
"src\\Sentry.Maui\\Sentry.Maui.csproj",
1111
"src\\Sentry\\Sentry.csproj",
12+
"test\\MauiTestUtils\\DeviceTests.Runners.SourceGen\\TestUtils.DeviceTests.Runners.SourceGen.csproj",
13+
"test\\MauiTestUtils\\DeviceTests.Runners\\TestUtils.DeviceTests.Runners.csproj",
14+
"test\\MauiTestUtils\\DeviceTests\\TestUtils.DeviceTests.csproj",
1215
"test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj",
16+
"test\\Sentry.Maui.Device.TestApp\\Sentry.Maui.Device.TestApp.csproj",
1317
"test\\Sentry.Maui.Tests\\Sentry.Maui.Tests.csproj",
1418
"test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj",
1519
"test\\Sentry.Testing\\Sentry.Testing.csproj",
1620
"test\\Sentry.Tests\\Sentry.Tests.csproj"
1721
]
1822
}
1923
}
24+
}

nuget.config

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
5+
<clear />
6+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
7+
8+
<!-- Needed for: Microsoft.DotNet.XHarness.TestRunners.Xunit -->
9+
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" protocolVersion="3" />
10+
11+
</packageSources>
12+
13+
<packageSourceMapping>
14+
<packageSource key="nuget.org">
15+
<package pattern="*" />
16+
</packageSource>
17+
<packageSource key="dotnet-eng">
18+
<package pattern="Microsoft.DotNet.XHarness.*" />
19+
</packageSource>
20+
</packageSourceMapping>
21+
</configuration>

scripts/parse-xunit2-xml.ps1

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
param([string] $File)
2+
3+
Set-StrictMode -Version Latest
4+
5+
[xml]$xml = Get-Content $File
6+
7+
function ElementText([System.Xml.XmlElement] $element)
8+
{
9+
$element.InnerText.Replace('\n', "`n").Replace('\t', "`t").Replace('\"', '"').Trim()
10+
}
11+
12+
$summary = "## Summary`n`n"
13+
$summary += "| Assembly | Passed | Failed | Skipped |`n"
14+
$summary += "| -------- | -----: | -----: | ------: |`n"
15+
$failures = ""
16+
foreach ($assembly in $xml.assemblies.assembly)
17+
{
18+
$summary += "| $($assembly.name) | $($assembly.passed) | $($assembly.failed) | $($assembly.skipped) |`n"
19+
20+
if ($assembly.failed -gt 0)
21+
{
22+
$failures += "### $($assembly.name)`n"
23+
foreach ($test in $assembly.collection.test)
24+
{
25+
if ($test.result -eq "Pass")
26+
{
27+
continue
28+
}
29+
30+
$failures += "#### $($test.name.Replace('\"', '"'))"
31+
if ($test.result -eq "Skip")
32+
{
33+
$failures += " - Skipped`n"
34+
$failures += "$(ElementText $test.reason)"
35+
}
36+
else
37+
{
38+
$failures += " - $($test.result)ed`n"
39+
if ($test.PSobject.Properties.name -match "output")
40+
{
41+
$failures += "$(ElementText $test.output)`n"
42+
}
43+
$failures += '```' + "`n"
44+
$failures += "$(ElementText $test.failure.message)`n"
45+
$failures += "$(ElementText $test.failure['stack-trace'])`n"
46+
$failures += '```'
47+
}
48+
$failures += "`n"
49+
}
50+
}
51+
}
52+
53+
$summary
54+
55+
if ($failures.Length -gt 0)
56+
{
57+
"## Unsuccessful tests`n$failures"
58+
}

scripts/run-device-tests.cmd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@echo off
2+
setlocal
3+
4+
pushd %~dp0
5+
6+
dotnet build -f net6.0-android ..\test\Sentry.Maui.Device.TestApp
7+
8+
where xharness >nul 2>nul
9+
if %ERRORLEVEL% NEQ 0 dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*"
10+
11+
if exist ..\test_output rmdir /q /s ..\test_output
12+
13+
xharness android test ^
14+
--app=..\test\Sentry.Maui.Device.TestApp\bin\Debug\net6.0-android\io.sentry.dotnet.maui.device.testapp-Signed.apk ^
15+
--package-name=io.sentry.dotnet.maui.device.testapp ^
16+
--output-directory=..\test_output
17+
18+
popd

scripts/run-device-tests.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
pushd "$(dirname "$0")" > /dev/null
4+
5+
dotnet build -f net6.0-android ../test/Sentry.Maui.Device.TestApp
6+
7+
if ! command -v xharness &> /dev/null
8+
then
9+
dotnet tool install Microsoft.DotNet.XHarness.CLI --global --version "1.*-*"
10+
fi
11+
12+
rm -rf ../test_output
13+
14+
xharness android test \
15+
--app=../test/Sentry.Maui.Device.TestApp/bin/Debug/net6.0-android/io.sentry.dotnet.maui.device.testapp-Signed.apk \
16+
--package-name=io.sentry.dotnet.maui.device.testapp \
17+
--output-directory=../test_output
18+
19+
popd > /dev/null

test/Directory.Build.props

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
</PropertyGroup>
1212

1313
<!-- configure xunit -->
14-
<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('windows'))">
14+
<ItemGroup Condition="!$([MSBuild]::IsOSPlatform('windows')) AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))==''">
1515
<Content Include="..\xunit.runner.json">
1616
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
1717
</Content>
1818
</ItemGroup>
19-
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('windows'))">
19+
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('windows')) AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))==''">
2020
<Content Include="..\xunit.runner.windows.json">
2121
<Link>xunit.runner.json</Link>
2222
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -41,11 +41,9 @@
4141
<Using Include="NSubstitute.Core" />
4242
<Using Include="NSubstitute.ReturnsExtensions" />
4343
<Using Include="Sentry.DsnSamples" Static="True" />
44-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
4544
<PackageReference Include="NSubstitute" Version="4.4.0" />
4645
<PackageReference Include="FluentAssertions" Version="6.7.0" />
4746
<PackageReference Include="xunit" Version="2.4.2" />
48-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
4947
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
5048
<PackageReference Include="Verify.Xunit" Version="17.10.2" />
5149
<PackageReference Include="Verify.DiffPlex" Version="1.3.0" />
@@ -54,4 +52,10 @@
5452
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.1.1" />
5553
</ItemGroup>
5654

55+
<!-- only non-platform-specific projects should include these packages -->
56+
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))==''">
57+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="All" />
58+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" PrivateAssets="All" />
59+
</ItemGroup>
60+
5761
</Project>

test/Directory.Build.targets

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<Import Project="..\Directory.Build.targets" />
3+
4+
<!-- platform-specific targets should not be marked as test projects -->
5+
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != ''">
6+
<IsTestProject>false</IsTestProject>
7+
</PropertyGroup>
8+
</Project>

test/MauiTestUtils/DeviceTests.Runners.SourceGen/AnalyzerReleases.Shipped.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### New Rules
2+
3+
Rule ID | Category | Severity | Notes
4+
--------|----------|----------|--------------------
5+
TST1001 | Logging | Info | Logging messages
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.CodeAnalysis;
2+
3+
namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen
4+
{
5+
[Generator]
6+
public class CodeBehindGenerator : ISourceGenerator
7+
{
8+
public void Initialize(GeneratorInitializationContext context)
9+
{
10+
//#if DEBUG
11+
//if (!System.Diagnostics.Debugger.IsAttached)
12+
// System.Diagnostics.Debugger.Launch();
13+
//#endif
14+
}
15+
16+
public void Execute(GeneratorExecutionContext context)
17+
{
18+
if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TargetFramework", out var targetFramework))
19+
return;
20+
21+
context.Log($"TargetFramework: {targetFramework}");
22+
23+
var generator = new RunnerGenerator(context, targetFramework);
24+
25+
generator?.Generate();
26+
}
27+
}
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Diagnostics;
2+
using Microsoft.CodeAnalysis;
3+
4+
namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen
5+
{
6+
static class GeneratorDiagnostics
7+
{
8+
public static readonly DiagnosticDescriptor LoggingMessage = new DiagnosticDescriptor(
9+
id: "TST1001",
10+
title: "Logging Message",
11+
messageFormat: "{0}",
12+
category: "Logging",
13+
DiagnosticSeverity.Info,
14+
isEnabledByDefault: true);
15+
16+
[Conditional("DEBUG")]
17+
public static void Log(this GeneratorExecutionContext context, string message) =>
18+
context.ReportDiagnostic(Diagnostic.Create(LoggingMessage, Location.None, message));
19+
}
20+
}

0 commit comments

Comments
 (0)