'dotnet test' 在 gitlab-runner 管道中找不到 nunit 测试

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

我有一个 NUnit 测试项目 (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>

以下调用用于测试:

dotnet test --no-build -c Release -v n src\%TESTPROJECT%\%TESTPROJECT%.csproj --logger "trx;LogFileName=testreport.trx"

如果我 运行 在本地,一切都按预期工作:

构建服务器上的相同调用未找到任何测试:

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

有人得到提示可能出了什么问题吗?测试项目 (Foo.Test.dll) 可用并存在于构建工件中。

我不得不在测试之前在构建管道上添加一个额外的 dotnet restore 命令,以恢复 project.assets.json。现在一切正常

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