Reputation: 2426
i have just started with XUnit and configuring Jenkins and i wanted to ask if there is a way to run XUnit Tests directly started by Jenkins and not with a windows batch command, that starts the console runner of XUnit.
I know there is the possibilty to run the XUnit tests by executing a Windows batch command via the Console Runner but im looking for a Plugin / whatever that for example includes the XUnit Runner and you only have to point to the dll so he starts the Tests and processes the XML output.
Upvotes: 10
Views: 15710
Reputation: 1
Something like this will work:
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"'
this scripts runs test for all xunit dlls in "Tests" folder. Also it will output test result in junit so you can simply publish to Jenkins by following line
junit '*.Test.xml'
Upvotes: 0
Reputation: 23098
Provided answers were really helpful, but I did not manage to use xUnitPlugin so I relied on ReportUnit to generate the results.
add NunitXml.TestLogger package to the test project in order to be able to use it as a custom logger
[Windows batch command] Run the tests and generate output "NUnit" style:
dotnet test "project.csproj" --no-build --verbosity normal --logger:"nunit;LogFilePath=xunit_results.xml"
[Windows batch command] Generate the report based on previous output
"path_to_report_unit\ReportUnit.exe" "path_to_results\xunit_results.xml" "path_to_results\xunit_results.html"
The html can easily be embedded in some e-mail if needed (e.g. Editable Email Notification -> Triggers -> set Attachments pattern to **\*xunit*.html
)
Upvotes: 0
Reputation: 91
You can make it work with xUnit Jenkins plugin.
1) Have xUnit plugin installed.
2) In your pipeline save an xml file with xUnit results (I used https://github.com/Faizan2304/LoggerExtensions to make it work with "dotnet test" command).
3) Publish results with this code:
step([$class: 'XUnitBuilder',
thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']],
tools: [[$class: 'XUnitDotNetTestType', pattern: '{path to your xml file}']]])
Upvotes: 6
Reputation: 73
The xUnit Jenkins Plugin now supports xUnit.net:
Version 1.93
* Added support for xUnit.net v2
Upvotes: 4
Reputation: 111625
No, there is not a Jenkins plugin for executing xUnit.net tests.
The simplest way will be to run a Windows batch command within a Jenkins job.
You can at least use the xUnit plugin to parse the test results XML file from xUnit.net and update the build outcome based on whether all tests passed or not.
Upvotes: 7