2017-04-07 202 views
4

我正在使用dotnet測試運行dotnet核心庫的單元測試。我像這樣在我的Jenkins奴隸上運行測試。Jenkins爲dotnet測試集成

dotnet test test/Turbine.Domain.UnitTest -xml mstest-reports/Turbine.Domain.UnitTest.xml 

測試報告看起來像這樣。

<?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.0" 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... 

我在我的Jenkins作業DSL中使用archiveXUnit塊試圖在報告中閱讀。

archiveXUnit { 
    msTest { 
    pattern('**/mstest-reports/*.xml') 
    } 
} 

Jenkins似乎看到報告。

記錄測試結果

[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. 

但它不解析,並結合在其報告結果。我沒有看到我的Jenkins構建儀表板上的測試報告。

任何想法?

回答

4

所以我使用的xUnit和TRX格式愉快地工作:

運行測試:

dotnet test test_dir\test_project.csproj --logger "trx;LogFileName=results\unit_tests.xml" 

但是使用這個給我了以下問題:

 
No test discoverer is registered to perform discovery of test cases. 
Register a test discoverer and try again. 

等等手動將xunit亞軍複製到測試項目的bin文件夾中修復了這個問題(是的,這是hacky):

copy packages\xunit.runner.visualstudio.2.2.0\build\_common\*.dll test_dir\bin\Release /Y 

我再增加一個發佈的xUnit測試步驟如下所示:

Jenkins xUnit Reporter

測試,那麼獲得該項目的正確報告和建立網頁。