【问题标题】:How to publish results using dotnet test command如何使用 dotnet test 命令发布结果
【发布时间】:2018-09-29 17:24:02
【问题描述】:

我有一个用 dotnet core 编写的测试项目。这需要以 XML 或 HTML 格式发布结果。有没有办法可以使用相同的命令将结果发布到特定目录?
--result-directory 不适合我

【问题讨论】:

标签: .net-core command-line-arguments dotnet-core-pack


【解决方案1】:

您可以通过执行dotnet test --help 查看所有dotnet test 选项。其中一个选项是-l, --logger,它提供了一些重要信息:

Specify a logger for test results.
Examples:
Log in trx format using a unqiue file name: --logger trx
Log in trx format using the specified file name: --logger "trx;LogFileName=<TestResults.trx>"
More info on logger arguments support:https://aka.ms/vstest-report

那个支持链接https://aka.ms/vstest-report,有完整的信息。

所以要回答你的具体问题,你可以说

dotnet test -l:trx;LogFileName=C:\temp\TestOutput.xml

将结果发布到特定目录。

另一个选项是在 test.csproj 中设置 MSBuild 属性:

<PropertyGroup>
  <VSTestLogger>trx</VSTestLogger>
  <VSTestResultsDirectory>C:\temp</VSTestResultsDirectory>
</PropertyGroup>

这告诉记录器将文件放在C:\temp 目录中。

【讨论】:

  • 我无法创建一个固定的报告文件,这个 dotnet 测试总是附加一个尾随时间戳Results File: C:\myapp\results_2019-04-08_14-24-38-379.trx。我想成为C:\myapp\results.trx,正如dotnet test myapp.csproj --logger trx;LogFileName=C:\temp\results --no-build --no-restore --configuration Release --verbosity q所期望的那样
  • @Eric Erhardt,我在哪里可以找到在 test.csproj 中设置 MSBuild 属性的文档?我看了又看,但找不到任何信息。谢谢
  • 不知道有没有官方文档,我也找不到。但是,我通过查看dotnet test 命令如何调用项目找到了这些属性。见github.com/dotnet/cli/blob/…
  • 仅供参考,我在使用 LogFileName 运行时遇到了问题,直到我将完整选项用引号括起来,例如-l:"trx;LogFileName=testresult.xml"。另请注意:未指定目录时,文件将进入TestResults 文件夹。
  • trx 代表什么?
【解决方案2】:

在遇到同样的问题后(​​我想以 JUnit 格式发布测试结果),我最终找到了JUnitTestLogger NuGet package

这是安装它的问题:

dotnet add package JUnitTestLogger --version 1.1.0

然后运行测试:

dotnet test --logger "junit;LogFilePath=path/to/your/test/results.xml"

【讨论】:

  • 税,我需要 xunit xml 记录器,因为“dotnet xunit”命令不再支持作为外部命令行工具。您的帖子让我找到了“XunitXml.TestLogger”,非常感谢,现在我正在使用 dotnet test --logger:"xunit;LogFilePath=test_result.xml" 来满足我的需要。
  • 我总是收到以下错误:No test logging was found with AssemblyQualifiedName, URI, or FriendlyName "junit"你知道怎么解决吗?
  • 确保在您正在执行测试的环境中运行 dotnet restore,以便 junit 程序集在路径上可用。
  • 效果很好,感谢分享。如何在解决方案文件下输出所有单元测试项目,似乎输出的 junit 报告总是最后一个单元测试项目。
【解决方案3】:

使用Eric Erhardt 的答案中提供的语法,我无法让它工作。

使用 TRX Logger 示例 here 我能够重新创建正确的语法。

dotnet test --logger:"trx;LogFileName=C:\Temp\TestResults.xml" MyLibraryToTest.dll

$ dotnet test --logger:"trx;LogFileName=C:\Temp\TestResults.xml" MyLibraryToTest.dll
Microsoft (R) Test Execution Command Line Tool Version 16.8.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Starting ChromeDriver 87.0.4280.88 (89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761}) on port 51459
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Results File: C:\Temp\TestResults.xml

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 7 s - MyLibraryToTest.dll (net5.0)

【讨论】:

    猜你喜欢
    • 2017-04-11
    • 2019-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多