Skip to content

Commit 25b7d46

Browse files
[tests] migrate nunit-console commands to MSBuild
The end goal here is to easily enable running tests on Windows. To enable this, a new `build-tools/scripts/RunNUnitTests.targets` file is needed. The `Makefile` will invoke this file so we aren't duplicating anything. We will continue with this approach in xamarin/xamarin-android, so running unit tests is simpler on Windows there, too. ## Usage (Windows): Run all tests: `msbuild build-tools/scripts/RunNUnitTests.targets` Filter based on the `--run` switch: `msbuild build-tools/scripts/RunNUnitTests.targets /p:Run=Java.Interop` Run tests on specific assemblies: `msbuild build-tools\scripts\RunNUnitTests.targets /p:TestAssembly="bin\TestDebug\Java.Interop.Tools.JavaCallableWrappers-Tests.dll;bin\TestDebug\LogcatParse-Tests.dll"` ## Usage (macOS/linux) `make` commands should remain unchanged. Existing environment variables should continue to work such as `RUNTIME`, `RUN`, `CONFIGURATION`, etc.
1 parent 4d5d2ff commit 25b7d46

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,7 @@ shell:
139139
define RUN_TEST
140140
MONO_TRACE_LISTENER=Console.Out \
141141
JAVA_INTEROP_GREF_LOG=g-$(basename $(notdir $(1))).txt $(if $(2),JAVA_INTEROP_LREF_LOG=l-$(basename $(notdir $(1))).txt,) \
142-
$(RUNTIME) $$MONO_OPTIONS --runtime=v4.0.0 \
143-
$(NUNIT_CONSOLE) $(NUNIT_EXTRA) $(1) \
144-
$(if $(RUN),-run:$(RUN)) \
145-
-xml=TestResult-$(basename $(notdir $(1))).xml \
146-
-output=bin/Test$(CONFIGURATION)/TestOutput-$(basename $(notdir $(1))).txt ;
142+
$(MSBUILD) $(MSBUILD_FLAGS) build-tools/scripts/RunNUnitTests.targets /p:TestAssembly=$(1) ;
147143
endef
148144

149145
run-tests: $(TESTS) bin/Test$(CONFIGURATION)/$(JAVA_INTEROP_LIB)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="RunTests" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<_TopDir>$(MSBuildThisFileDirectory)..\..</_TopDir>
6+
<_RuntimeVersion Condition=" '$(OS)' != 'Windows_NT' ">--runtime=v4.0.0</_RuntimeVersion>
7+
<_Runtime Condition=" '$(RUNTIME)' != '' ">$(RUNTIME)</_Runtime>
8+
<_Runtime Condition=" '$(RUNTIME)' == '' And '$(OS)' != 'Windows_NT' ">mono</_Runtime>
9+
<_NUnit>$(_Runtime) $(_RuntimeVersion) packages\NUnit.Runners.2.6.3\tools\nunit-console.exe</_NUnit>
10+
<_Run Condition=" '$(RUN)' != '' ">--run=&quot;$(RUN)&quot;</_Run>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<_TestAssembly Include="$(_TopDir)\bin\Test$(Configuration)\*-*Tests.dll" Condition=" '$(TestAssembly)' == '' " />
14+
<_TestAssembly Include="$(TestAssembly)" Condition=" '$(TestAssembly)' != '' " />
15+
</ItemGroup>
16+
<Target Name="RunTests">
17+
<Exec
18+
Command="$(_NUnit) $(NUNIT_EXTRA) %(_TestAssembly.Identity) $(_Run) --result=&quot;TestResult-%(Filename).xml&quot; --output=bin\Test$(Configuration)\TestOutput-%(Filename).txt"
19+
WorkingDirectory="$(_TopDir)"
20+
ContinueOnError="True"
21+
/>
22+
</Target>
23+
</Project>

0 commit comments

Comments
 (0)