'dotnet test' is not finding nunit tests in gitlab-runner pipeline

余生颓废 提交于 2020-01-15 09:26:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!