用于 dotnet 测试的 Jenkins 集成 [英] Jenkins integration for dotnet test
问题描述
我正在使用 dotnet test 运行 dotnet 核心库的单元测试.我像这样在我的 Jenkins slave 上运行测试.
dotnet test test/Turbine.Domain.UnitTest -xml mstest-reports/Turbine.Domain.UnitTest.xml
测试报告是这样的.
<错误/><collection total="3"passed="3" failed="0" skipped="0" name="Turbine.Domain.Tests.AccumulatePositionsTests 的测试集合" time="0.052"><test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByPortfolioIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByPortfolioIndex" time="0.0402475" result="Pass"/><test name="Turbine.Domain.Tests.AccumulatePositionsTests.LotEventsTriggerPositionEventsImmediately" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="LotEventsTriggerPositionEventsImmediately" time="0.0102925" result="<test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByDefaultIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByDefaultIndex" time="0.0012357" result="Pass"/></集合><collection total="4"passed="4" failed="0" skipped="0" name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests 的测试集合" time="0.087"><test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.MarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="MarketValueHandlesNegativeAmounts" time="0.0826806" result="Pass"/><test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.CanProduceFirmSummaryFromSnapshot" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="CanProduceFirmSummaryFromSnapshot" time="0.0012097" result="Pass"/><test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.GrossMarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="GrossMarketValueHandlesNegativeAmounts" time="0.0020873"/gt="Pass" 结果<test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.FirmSummaryProducesOutputOnQuote" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="FirmSummaryProducesOutputOnQuote" time="0.0010767" result="Pass"/></集合>等等...
我在我的 Jenkins 工作 DSL 中使用了一个 archiveXUnit
块来尝试阅读报告.
archiveXUnit {msTest {模式('**/mstest-reports/*.xml')}}
詹金斯似乎看到了报告.
记录测试结果
[xUnit] [INFO] - 开始录制.[xUnit] [INFO] - 处理 MSTest 版本 N/A(默认)[xUnit] [INFO] - [MSTest-Version N/A(默认)] - 找到 1 个测试报告文件,其模式为 '**/mstest-reports/*.xml' 相对于'/home/jenkins'/workspace/routing/Turbine/build_Turbine' 用于测试框架MSTest-Version N/A(默认)".[xUnit] [INFO] - 检查失败测试"阈值.[xUnit] [INFO] - 检查跳过的测试"阈值.[xUnit] [INFO] - 将构建状态设置为 SUCCESS[xUnit] [INFO] - 停止录音.
但它并没有在其报告中解析和合并结果.我在 Jenkins 构建仪表板上没有看到测试报告.
有什么想法吗?
您可以使用以下 Pipeline 代码来运行和发布 dotnet 核心测试结果:
节点{阶段结帐"清洁Ws()结帐 scm建造"阶段bat ""C:/Program Files/dotnet/dotnet.exe" restore "${workspace}/YourProject.sln""bat ""C:/Program Files/dotnet/dotnet.exe" build "${workspace}/YourProject.sln""阶段单元测试"bat returnStatus: true, script: ""C:/Program Files/dotnet/dotnet.exe" test "${workspace}/YourProject.sln" --logger "trx;LogFileName=unit_tests.xml"--no-build"step([$class: 'MSTestPublisher', testResultsFile:"**/unit_tests.xml", failOnError: true, keepLongStdio: true])}
我已经上传了一些我制作的示例到我的 GitHub 供大家使用和贡献,请随意查看:
I'm running a unit test of a dotnet core library using dotnet test. I run the test on my Jenkins slave like this.
dotnet test test/Turbine.Domain.UnitTest -xml mstest-reports/Turbine.Domain.UnitTest.xml
The test report looks like this.
<?xml version="1.0" encoding="utf-8"?>
<assemblies>
<assembly name="Turbine.Domain.UnitTest.dll" environment="64-bit .NET (unknown version) [collection-per-class, parallel (8 threads)]" test-framework="xUnit.net 2.1.0.3179" run-date="2017-04-07" run-time="13:34:31" total="31" passed="31" failed="0" skipped="0" time="0.170" errors="0">
<errors />
<collection total="3" passed="3" failed="0" skipped="0" name="Test collection for Turbine.Domain.Tests.AccumulatePositionsTests" time="0.052">
<test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByPortfolioIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByPortfolioIndex" time="0.0402475" result="Pass" />
<test name="Turbine.Domain.Tests.AccumulatePositionsTests.LotEventsTriggerPositionEventsImmediately" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="LotEventsTriggerPositionEventsImmediately" time="0.0102925" result="Pass" />
<test name="Turbine.Domain.Tests.AccumulatePositionsTests.CanAccumulatePositionsByDefaultIndex" type="Turbine.Domain.Tests.AccumulatePositionsTests" method="CanAccumulatePositionsByDefaultIndex" time="0.0012357" result="Pass" />
</collection>
<collection total="4" passed="4" failed="0" skipped="0" name="Test collection for Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" time="0.087">
<test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.MarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="MarketValueHandlesNegativeAmounts" time="0.0826806" result="Pass" />
<test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.CanProduceFirmSummaryFromSnapshot" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="CanProduceFirmSummaryFromSnapshot" time="0.0012097" result="Pass" />
<test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.GrossMarketValueHandlesNegativeAmounts" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="GrossMarketValueHandlesNegativeAmounts" time="0.0020873" result="Pass" />
<test name="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests.FirmSummaryProducesOutputOnQuote" type="Turbine.Domain.Tests.Queries.AnalyticsSummaryTests" method="FirmSummaryProducesOutputOnQuote" time="0.0010767" result="Pass" />
</collection>
etc...
I use an archiveXUnit
block in my Jenkins jobs DSL to try and read in the report.
archiveXUnit {
msTest {
pattern('**/mstest-reports/*.xml')
}
}
Jenkins appears to see the report.
Recording test results
[xUnit] [INFO] - Starting to record.
[xUnit] [INFO] - Processing MSTest-Version N/A (default)
[xUnit] [INFO] - [MSTest-Version N/A (default)] - 1 test report file(s) were found with the pattern '**/mstest-reports/*.xml' relative to '/home/jenkins/workspace/routing/Turbine/build_Turbine' for the testing framework 'MSTest-Version N/A (default)'.
[xUnit] [INFO] - Check 'Failed Tests' threshold.
[xUnit] [INFO] - Check 'Skipped Tests' threshold.
[xUnit] [INFO] - Setting the build status to SUCCESS
[xUnit] [INFO] - Stopping recording.
But it isn't parsing and incorporating the results in its report. I don't see the test report on my Jenkins build dashboard.
Any ideas?
You can use the following Pipeline code to run and publish the dotnet core test results:
node {
stage 'Checkout'
cleanWs()
checkout scm
stage 'Build'
bat ""C:/Program Files/dotnet/dotnet.exe" restore "${workspace}/YourProject.sln""
bat ""C:/Program Files/dotnet/dotnet.exe" build "${workspace}/YourProject.sln""
stage 'UnitTests'
bat returnStatus: true, script: ""C:/Program Files/dotnet/dotnet.exe" test "${workspace}/YourProject.sln" --logger "trx;LogFileName=unit_tests.xml" --no-build"
step([$class: 'MSTestPublisher', testResultsFile:"**/unit_tests.xml", failOnError: true, keepLongStdio: true])
}
I have uploaded some examples that I made to my GitHub for everyone to use and contribute, feel free to take a look:
https://github.com/avrum/JenkinsFileFor.NETCore
Those pipline jenkinsfile will add this pipline template to your build:
这篇关于用于 dotnet 测试的 Jenkins 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!