如何使用dotnet test命令发布结果

Rag*_*pur 11 command-line-arguments .net-core dotnet-core-pack

我有一个用dotnet核心编写的测试项目.这需要以xml或html格式发布结果.有没有办法可以使用相同的命令将结果发布到特定目录? - result-directory对我不起作用

Eri*_*rdt 19

您可以dotnet test通过执行来查看所有选项dotnet test --help.其中一个选项是-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
Run Code Online (Sandbox Code Playgroud)

该支持链接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>
Run Code Online (Sandbox Code Playgroud)

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

  • 仅供参考,我在使用“LogFileName”运行时遇到了麻烦,直到我将完整选项用引号引起来,例如“-l:”trx;LogFileName = testresult.xml“。另请注意:如果未指定目录,文件将进入“TestResults”文件夹。 (3认同)

And*_*que 9

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

只需安装即可:

dotnet add package JUnitTestLogger --version 1.1.0
Run Code Online (Sandbox Code Playgroud)

然后以以下方式运行测试:

dotnet test --logger "junit;LogFilePath=path/to/your/test/results.xml"
Run Code Online (Sandbox Code Playgroud)

  • 税收,我需要使用xunit xml记录器,并且由于不再支持“ dotnet xunit”命令作为外部命令行工具。您的帖子使我找到了“ XunitXml.TestLogger”,非常感谢,现在我正在使用dotnet test --logger:“ xunit; LogFilePath = test_result.xml”,它可以满足我的需要。 (3认同)
  • 我总是收到以下错误:`未找到带有 AssemblyQualifiedName、URI 或FriendlyName“junit”的测试日志记录`您知道如何修复它吗? (2认同)
  • 确保在执行测试的环境中运行 dotnet Restore,以便 junit 程序集在路径上可用。 (2认同)

Nie*_* R. 6

我无法使用Eric Erhardt的答案中提供的语法来使其工作。

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

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)
Run Code Online (Sandbox Code Playgroud)


小智 5

我今天使用 nuget 包 JunitXml.TestLogger 版本 3.0.114 取得了成功: https://www.nuget.org/packages/JunitXml.TestLogger/

添加为依赖项:
dotnet add package JunitXml.TestLogger --version 3.0.114

一旦添加为依赖项,只需执行以下操作即可:
dotnet test --logger:"junit;LogFilePath=dotnet-test-result.xml"

截至今天,JunitXml.TestLogger 的星星数量是另一个答案中提到的 nuget 包 JUnitTestLogger 的四倍。JunitXml.TestLogger 正在积极维护,而 JUnitTestLogger 已经 2 年没有被触及了。