Skip to content

Commit 5ff1702

Browse files
authored
[tests] Use dotnet test to run AndroidSdk-Tests (#102)
Update `Xamarin.Android.Tools.AndroidSdk-Tests.csproj` to target only `netcoreapp3.1`, and updates all test running logic to use `dotnet test`. This allows us to remove the `globalPackagesFolder` override from `NuGet.config`, as `NUnit.ConsoleRunner` is no longer referenced or used. The YAML pipeline has also been consolidated a bit to reduce step duplication. A matrix strategy is now used to run the same steps in parallel on both macOS and Windows. OS-specific steps are now hidden behind a condition so that we don't duplicate artifact uploading and publishing.
1 parent ad80a42 commit 5ff1702

File tree

9 files changed

+69
-87
lines changed

9 files changed

+69
-87
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ bin
1212
**/obj
1313
packages/
1414
TestResult-*.xml
15-
.vs/
15+
**/TestResults/*.trx
16+
.vs/

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"recommendations": [
33
"ms-vscode.csharp",
44
"ms-vscode.mono-debug",
5-
"wghats.vscode-nxunit-test-adapter",
5+
"hbenl.vscode-test-explorer",
6+
"derivitec-ltd.vscode-dotnet-adapter",
67
"visualstudioexptteam.vscodeintellicode",
78
]
89
}

.vscode/settings.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"nxunitExplorer.nunit": "packages/NUnit.ConsoleRunner.3.9.0/tools/nunit3-console.exe",
3-
"nxunitExplorer.modules": [
4-
"bin/TestDebug/Xamarin.Android.Tools.AndroidSdk-Tests.dll"
5-
]
6-
}
2+
"dotnetCoreExplorer.searchpatterns": "bin/Test*net*/**/*-Tests.dll",
3+
}

.vscode/tasks.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
{
3131
"label": "Run Unit Tests",
3232
"type": "shell",
33-
"command": "make run-all-tests",
33+
"command": "dotnet",
34+
"args": [
35+
"test",
36+
"${workspaceFolder}/tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj"
37+
],
3438
"group": {
3539
"kind": "test",
3640
"isDefault": true

Makefile

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
CONFIGURATION := Debug
2-
NUNIT_CONSOLE := packages/nunit.consolerunner/3.9.0/tools/nunit3-console.exe
32
OS := $(shell uname)
4-
RUNTIME := mono --debug=casts
53
V ?= 0
64

75
include build-tools/scripts/msbuild.mk
@@ -15,26 +13,6 @@ clean:
1513
prepare:
1614
nuget restore Xamarin.Android.Tools.sln
1715

18-
run-all-tests: run-nunit-tests
19-
20-
# $(call RUN_NUNIT_TEST,filename,log-lref?)
21-
define RUN_NUNIT_TEST
22-
MONO_TRACE_LISTENER=Console.Out \
23-
$(RUNTIME) \
24-
$(NUNIT_CONSOLE) $(NUNIT_EXTRA) $(1) \
25-
$(if $(RUN),-run:$(RUN)) \
26-
--result="TestResult-$(basename $(notdir $(1))).xml" \
27-
-output=bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt \
28-
|| true ; \
29-
if [ -f "bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt" ] ; then \
30-
cat bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt ; \
31-
fi
32-
endef
33-
34-
$(NUNIT_CONSOLE): prepare
35-
36-
NUNIT_TESTS = \
37-
bin/Test$(CONFIGURATION)/Xamarin.Android.Tools.AndroidSdk-Tests.dll
38-
39-
run-nunit-tests: $(NUNIT_TESTS)
40-
$(foreach t,$(NUNIT_TESTS), $(call RUN_NUNIT_TEST,$(t),1))
16+
run-all-tests:
17+
dotnet test -l "console;verbosity=detailed" -l trx \
18+
tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj

NuGet.config

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
3-
Our testing infrastructure depends on a known location for:
4-
- nunit3-console.exe
5-
-->
62
<configuration>
73
<packageSources>
84
<clear />
@@ -15,7 +11,4 @@
1511
<!-- Android binary, to support delta APK install -->
1612
<add key="xamarin.android util" value="https://pkgs.dev.azure.com/xamarin/public/_packaging/Xamarin.Android/nuget/v3/index.json" />
1713
</packageSources>
18-
<config>
19-
<add key="globalPackagesFolder" value="packages" />
20-
</config>
2114
</configuration>

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ The default `make all` target accepts the following optional
3838

3939
# Build
4040

41-
To build **xamarin-android-tools**, first prepare the project:
41+
To build **xamarin-android-tools**:
42+
43+
msbuild /restore Xamarin.Android.Tools.sln
44+
45+
Alternatively, first prepare the project:
4246

4347
make prepare
4448

@@ -53,7 +57,7 @@ Next, run `make`:
5357

5458
To run the unit tests:
5559

56-
make run-all-tests
60+
dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -l "console;verbosity=detailed"
5761

5862
# Build Output Directory Structure
5963

azure-pipelines.yaml

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,82 @@ pr:
1111
# Global variables
1212
variables:
1313
DotNetCoreVersion: 3.1.100
14-
HostedMac: Hosted Mac Internal
15-
HostedWinVS2019: Hosted Windows 2019 with VS2019
1614

1715
jobs:
18-
- job: windows
19-
displayName: windows
20-
pool: $(HostedWinVS2019)
16+
- job: build
17+
displayName: Build and Test
18+
timeoutInMinutes: 60
19+
cancelTimeoutInMinutes: 2
20+
21+
strategy:
22+
matrix:
23+
macOS:
24+
vmImage: macOS-10.15
25+
win2019:
26+
vmImage: windows-2019
27+
28+
pool:
29+
vmImage: $(vmImage)
30+
31+
workspace:
32+
clean: all
33+
2134
steps:
35+
- checkout: self
36+
clean: true
37+
2238
- task: UseDotNet@2
2339
displayName: Use .NET Core $(DotNetCoreVersion)
2440
inputs:
2541
version: $(DotNetCoreVersion)
42+
2643
- task: NuGetToolInstaller@0
2744
displayName: 'Install NuGet'
2845
inputs:
2946
versionSpec: 5.x
47+
48+
- script: |
49+
dotnet tool install --global boots
50+
boots https://download.mono-project.com/archive/6.12.0/macos-10-universal/MonoFramework-MDK-6.12.0.107.macos10.xamarin.universal.pkg
51+
displayName: Install Mono 6.12
52+
condition: and(succeeded(), eq(variables['agent.os'], 'Darwin'))
53+
3054
- task: NuGetCommand@2
3155
displayName: 'NuGet Restore'
3256
inputs:
3357
restoreSolution: Xamarin.Android.Tools.sln
3458
feedsToUse: config
3559
nugetConfigPath: NuGet.config
60+
3661
- task: MSBuild@1
3762
displayName: 'Build solution Xamarin.Android.Tools.sln'
3863
inputs:
3964
solution: Xamarin.Android.Tools.sln
40-
- task: VSTest@2
65+
66+
- task: DotNetCoreCLI@2
4167
displayName: 'Run Tests'
4268
inputs:
43-
testAssemblyVer2: 'bin\TestDebug\*-Tests.dll'
44-
testRunTitle: windows-tests
69+
command: test
70+
projects: bin/TestDebug-net*/**/*-Tests.dll
71+
testRunTitle: Xamarin.Android.Tools Tests - $(vmImage)
72+
4573
- powershell: |
4674
$hashOfLastVersionChange = & "git" "log" "--follow" "-1" "--pretty=%H" "nuget.version"
4775
$commitsSinceVersionChange = & "git" "rev-list" "--count" "$hashOfLastVersionChange..HEAD"
4876
$majorMinor = Get-Content "nuget.version"
4977
$version = "$majorMinor.$commitsSinceVersionChange"
5078
Write-Host "##vso[task.setvariable variable=xat.nuget.version]$version"
79+
condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT'))
80+
5181
- task: MSBuild@1
5282
displayName: 'Build NuGet'
5383
inputs:
5484
solution: 'src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj'
5585
msbuildArguments: '/t:pack /p:Version=$(xat.nuget.version) /p:OutputPath=$(Build.ArtifactStagingDirectory)'
86+
condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT'))
87+
5688
- task: PublishBuildArtifacts@1
5789
displayName: Upload Artifacts
5890
inputs:
5991
pathtoPublish: $(Build.ArtifactStagingDirectory)
60-
- job: mac
61-
displayName: mac
62-
pool: $(HostedMac)
63-
steps:
64-
- task: UseDotNet@2
65-
displayName: Use .NET Core $(DotNetCoreVersion)
66-
inputs:
67-
version: $(DotNetCoreVersion)
68-
- script: |
69-
dotnet tool install --global boots
70-
boots https://download.mono-project.com/archive/6.4.0/macos-10-universal/MonoFramework-MDK-6.4.0.198.macos10.xamarin.universal.pkg
71-
displayName: Install Mono 6.4
72-
- script: make prepare CONFIGURATION=$(Build.Configuration)
73-
displayName: make prepare
74-
75-
- script: make all CONFIGURATION=$(Build.Configuration)
76-
displayName: make all
77-
78-
- script: make run-all-tests CONFIGURATION=$(Build.Configuration)
79-
displayName: make run-all-tests
80-
81-
- task: PublishTestResults@2
82-
condition: always()
83-
inputs:
84-
testResultsFormat: NUnit
85-
testResultsFiles: TestResult*.xml
86-
testRunTitle: mac-tests
87-
failTaskOnFailedTests: true
92+
condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT'))

tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net461;netcoreapp3.1</TargetFrameworks>
4+
<!-- $(TargetFrameworks) is used to allow the $(TargetFramework) check in Directory.Build.props to work.
5+
If $(TargetFramework) is declared here instead, it will not be evaluated before Directory.Build.props
6+
is loaded and the wrong $(TestOutputFullPath) will be used. -->
7+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
58
<IsPackable>false</IsPackable>
6-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
7-
</PropertyGroup>
8-
9-
<PropertyGroup>
109
<OutputPath>$(TestOutputFullPath)</OutputPath>
10+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="nunit" Version="3.11.0" />
15-
<PackageReference Include="NUnit.ConsoleRunner" Version="3.9.0" />
16-
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
14+
<PackageReference Include="NUnit" Version="3.12.0" />
15+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
16+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
1817
</ItemGroup>
1918

2019
<ItemGroup>

0 commit comments

Comments
 (0)