如何 运行 使用 Jenkins 进行 XUnit 测试
How to run XUnit Tests with Jenkins
我刚刚开始使用 XUnit 并配置 Jenkins,我想问一下是否有一种方法可以 运行 XUnit 测试直接由 Jenkins 启动,而不是使用 windows 批处理命令,启动XUnit 的控制台 运行ner。
我知道可以通过 Console Runner 执行 Windows 批处理命令来 运行 XUnit 测试,但我正在寻找一个插件/例如包括 XUnit Runner 和您只需指向 dll,以便他启动测试并处理 XML 输出。
不,没有用于执行 xUnit.net 测试的 Jenkins 插件。
最简单的方法是 运行 在 Jenkins 作业中执行 Windows 批处理命令。
您至少可以使用 xUnit plugin 从 xUnit.net 解析测试结果 XML 文件,并根据所有测试是否通过来更新构建结果。
The xUnit Jenkins Plugin now supports xUnit.net:
Version 1.93
* Added support for xUnit.net v2
你可以让它与 xUnit Jenkins 插件一起工作。
1) 安装了 xUnit 插件。
2) 在您的管道中保存一个包含 xUnit 结果的 xml 文件(我使用 https://github.com/Faizan2304/LoggerExtensions 使其与 "dotnet test" 命令一起使用)。
3) 使用此代码发布结果:
step([$class: 'XUnitBuilder',
thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']],
tools: [[$class: 'XUnitDotNetTestType', pattern: '{path to your xml file}']]])
提供的答案真的很有帮助,但我没有设法使用 xUnitPlugin,所以我依靠 ReportUnit 来生成结果。
add NunitXml.TestLogger 打包到测试项目,以便能够将其用作自定义记录器
[Windows 批处理命令] 运行 测试并生成输出 "NUnit" 样式:
dotnet test "project.csproj" --no-build --verbosity normal --logger:"nunit;LogFilePath=xunit_results.xml"
[Windows批处理命令]根据之前的输出生成报告
"path_to_report_unit\ReportUnit.exe" "path_to_results\xunit_results.xml" "path_to_results\xunit_results.html"
如果需要,html 可以很容易地嵌入到某些电子邮件中(例如可编辑电子邮件通知 -> 触发器 -> 将附件模式设置为 **\*xunit*.html
)
像这样的东西会起作用:
bat'For /R .\Tests\ %%G IN (bin\release\*.test.dll) do packages\xunit.runner.console.2.4.1\tools\net461\xunit.console.x86.exe "%%G" -junit "%%~nG.xml"'
此脚本对“测试”文件夹中的所有 xunit dll 运行测试。它还会在 junit 中输出测试结果,因此您可以通过以下行简单地发布到 Jenkins
junit'*.Test.xml'
我刚刚开始使用 XUnit 并配置 Jenkins,我想问一下是否有一种方法可以 运行 XUnit 测试直接由 Jenkins 启动,而不是使用 windows 批处理命令,启动XUnit 的控制台 运行ner。
我知道可以通过 Console Runner 执行 Windows 批处理命令来 运行 XUnit 测试,但我正在寻找一个插件/例如包括 XUnit Runner 和您只需指向 dll,以便他启动测试并处理 XML 输出。
不,没有用于执行 xUnit.net 测试的 Jenkins 插件。
最简单的方法是 运行 在 Jenkins 作业中执行 Windows 批处理命令。
您至少可以使用 xUnit plugin 从 xUnit.net 解析测试结果 XML 文件,并根据所有测试是否通过来更新构建结果。
The xUnit Jenkins Plugin now supports xUnit.net:
Version 1.93
* Added support for xUnit.net v2
你可以让它与 xUnit Jenkins 插件一起工作。
1) 安装了 xUnit 插件。
2) 在您的管道中保存一个包含 xUnit 结果的 xml 文件(我使用 https://github.com/Faizan2304/LoggerExtensions 使其与 "dotnet test" 命令一起使用)。
3) 使用此代码发布结果:
step([$class: 'XUnitBuilder',
thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']],
tools: [[$class: 'XUnitDotNetTestType', pattern: '{path to your xml file}']]])
提供的答案真的很有帮助,但我没有设法使用 xUnitPlugin,所以我依靠 ReportUnit 来生成结果。
add NunitXml.TestLogger 打包到测试项目,以便能够将其用作自定义记录器
[Windows 批处理命令] 运行 测试并生成输出 "NUnit" 样式:
dotnet test "project.csproj" --no-build --verbosity normal --logger:"nunit;LogFilePath=xunit_results.xml"
[Windows批处理命令]根据之前的输出生成报告
"path_to_report_unit\ReportUnit.exe" "path_to_results\xunit_results.xml" "path_to_results\xunit_results.html"
如果需要,html 可以很容易地嵌入到某些电子邮件中(例如可编辑电子邮件通知 -> 触发器 -> 将附件模式设置为 **\*xunit*.html
)
像这样的东西会起作用:
bat'For /R .\Tests\ %%G IN (bin\release\*.test.dll) do packages\xunit.runner.console.2.4.1\tools\net461\xunit.console.x86.exe "%%G" -junit "%%~nG.xml"'
此脚本对“测试”文件夹中的所有 xunit dll 运行测试。它还会在 junit 中输出测试结果,因此您可以通过以下行简单地发布到 Jenkins
junit'*.Test.xml'