【问题标题】:The dotnet test command ignores the creation of a file with NUnit resultsdotnet test 命令忽略创建具有 NUnit 结果的文件
【发布时间】:2019-09-26 04:23:40
【问题描述】:

我在 .NET Core + NUnit.TestLogger 上有 NUnit 测试项目 (https://github.com/spekt/nunit.testlogger)
我通过 cmd 对本地机器或 teamcity 运行测试:

dotnet test --logger:nunit

我得到了预期的结果:

Results File: D:\<PATH TO MY SOLUTION>\Source\Tests\TestResults\TestResults.xml

但如果我通过 .NET CLI 在 Teamcity 上运行测试,则不会创建 TestResults.xml 文件。
为什么?

也就是说,如果我通过命令行运行 dotnet test,则会创建结果文件,如果通过 .NET CLI (dotnet test),则不会创建文件

UPD:构建日志

[13:48:22][Step 3/5] dotnet.exe test MySolution.sln --logger:"nunit" @C:\teamcity-agents\BuildAgent-1\temp\agentTmp\730f901563fb4fd9b8d130e76c50cb20.rsp
[13:48:22][Step 3/5] test (5s)
[13:48:22][test] Starting: "C:\Program Files\dotnet\dotnet.exe" test MySolution.sln --logger:"nunit" @C:\teamcity-agents\BuildAgent-1\temp\agentTmp\730f901563fb4fd9b8d130e76c50cb20.rsp
[13:48:22][test] in directory: C:\teamcity-agents\BuildAgent-1\work\21fca25db91ea807
[13:48:24][test] Build started, please wait...
[13:48:24][test] Build completed.
[13:48:24][test] Test run for C:\teamcity-agents\BuildAgent-1\work\21fca25db91ea807\Source\Tests\bin\Debug\netcoreapp2.1\MySolution.dll(.NETCoreApp,Version=v2.1)
[13:48:24][test] Microsoft (R) Test Execution Command Line Tool Version 15.9.0
[13:48:24][test] Copyright (c) Microsoft Corporation.  All rights reserved.
[13:48:24][test] 
[13:48:24][test] Starting test execution, please wait...
[13:48:25][test] NUnit Adapter 3.13.0.0: Test execution started
[13:48:25][test] Running all tests in C:\teamcity-agents\BuildAgent-1\work\21fca25db91ea807\Source\Tests\bin\Debug\netcoreapp2.1\MySolution.dll
[13:48:25][test]    NUnit3TestExecutor converted 54 of 54 NUnit test cases
...
[13:48:27][test] Total tests: 52. Passed: 52. Failed: 0. Skipped: 0.
[13:48:27][test] Test Run Successful.
[13:48:27][test] Test execution time: 2,8774 Seconds
[13:48:27][test] 
[13:48:27][test] Build succeeded.
[13:48:27][test]     0 Warning(s)
[13:48:27][test]     0 Error(s)
[13:48:27][test] 
[13:48:27][test] Time Elapsed 00:00:03.96
[13:48:27][test] 
[13:48:27][test] Process exited with code 0

【问题讨论】:

  • 用引号试试:--logger:"nunit"
  • @Peska,我试过了,没有解决问题
  • 没有更多的想法??

标签: teamcity nunit-3.0 dotnet-cli


【解决方案1】:

我找到了解决方案。 首先@p4ulinux 答案有效,但在这种情况下,您错过了与 TeamCity 的集成,因此测试用例不会出现在“测试”选项卡中。 所以,我的解决方案是在 .runsettings 文件中添加下一行:

<LoggerRunSettings>
<Loggers>
  <Logger friendlyName="nunit" enabled="True">
    <Configuration>
      <LogFileName>test-result.xml</LogFileName>
    </Configuration>
  </Logger>
</Loggers>

然后在设置文件部分指出您的 .runsettins 在步骤设置中的位置:

Settings file Section

结果文件将出现在 .csproj 文件旁边的 TestResults 文件夹中。

这对我很有用!希望它对其他人有用!

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我通过选择 RunnerType 作为命令行而不是 dot net cli 解决了这个问题。您需要按如下方式对其进行配置:

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2020-04-03
      • 2018-09-29
      • 2017-04-11
      • 2022-11-21
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 1970-01-01
      相关资源
      最近更新 更多