我如何在 jenkins 中使用 xunit (.net core) 测试结果?

How can i use xunit (.net core) test results in jenkins?

我有一个 asp.net 核心应用程序,其中有一些用 XUnit 编写的测试。我如何使用像 jenkins 这样的工具来使用测试结果?

我在这个问题上苦苦挣扎,所以我决定根据我的经验分享我的答案。

为了使用测试结果,我们需要将它们输出到 XML 文件中,供解析器稍后使用。 xml 需要采用解析器知道如何读取的格式。

默认情况下,当运行宁dotnet test, it will output the test results into the console. In order to save those results into a file, we should use the "--logger" param. the logger param can accept a logger than will parse the test results into the desired format. in order to parse them into an xunit xml test files that can be used by tools like jenkins, we need to use an external logger named XunitXml.TestLogger。现在我们可以运行以下命令:

dotnet test --test-adapter-path:. --logger:xunit

这会将结果导出到您拥有的每个项目中的 TestResults 文件夹中。 现在我们可以通过任何工具使用这些文件,比如 jenkins 来解析这些文件。 jenkins 有一个名为 Xunit 的插件(多么原始)专门用于此目的。它甚至可以让你设置一些错误阈值等

更新:害怕 jenkins,我发现有一些插件允许您将点 TRX 结果(dotnet 知道本地导出)转换为 XUnit 格式。这可能会简化它并为您节省额外的依赖性。 MSTest 如果其中之一 - https://wiki.jenkins.io/display/JENKINS/MSTest+Plugin