问题
I have a solution with a NUnit
testproject (Foo.Test
).
+-- src
| +-- Foo.Gui
| +-- Foo.Test
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TestResults\**" />
<EmbeddedResource Remove="TestResults\**" />
<None Remove="TestResults\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="GitVersionTask" Version="5.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Foo.Gui\Foo.Gui.csproj" />
</ItemGroup>
</Project>
The following call is used for testing:
dotnet test --no-build -c Release -v n src\%TESTPROJECT%\%TESTPROJECT%.csproj --logger "trx;LogFileName=testreport.trx"
If I run it local, everything is working as expected:
The same call on build server is not finding any test:
gitlab-ci.yml
test:solution:
stage: test
script:
- dotnet test --no-build -c Release -v n src\$env:TESTPROJECT\$env:TESTPROJECT.csproj --logger "trx;LogFileName=testreport.trx"
after_script:
- trx2junit src\$env:TESTPROJECT\Testresults\testreport.trx
artifacts:
reports:
junit: src\$env:TESTPROJECT\Testresults\testreport.xml
Someone got a hint what can be wrong? The Testproject (Foo.Test.dll) is available and present in the build artifacts.
回答1:
I had to add an additional dotnet restore
command on the build pipeline before testing, to restore the project.assets.json
. Now everything is working as expected 😮
test:solution:
stage: test
script:
- dotnet restore src
- dotnet test --no-build -c Release -v n src\$env:TESTPROJECT\$env:TESTPROJECT.csproj --logger "trx;LogFileName=testreport.trx"
after_script:
- trx2junit src\$env:TESTPROJECT\Testresults\testreport.trx
artifacts:
reports:
junit: src\$env:TESTPROJECT\Testresults\testreport.xml
来源:https://stackoverflow.com/questions/58993042/dotnet-test-is-not-finding-nunit-tests-in-gitlab-runner-pipeline