Jenkins integration for dotnet test
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:
So I'm using xUnit and the trx format which works happily:
Run Tests:
dotnet test test_dir\test_project.csproj --logger "trx;LogFileName=results\unit_tests.xml"
However using this gives me the following issue:
No test discoverer is registered to perform discovery of test cases. Register a test discoverer and try again.
And so copying the xunit runner manually to the bin folder of the test project fixes this (yes this is hacky):
copy packages\xunit.runner.visualstudio.2.2.0\build\_common\*.dll test_dir\bin\Release /Y
I then add a Publish xUnit tests step as shown:
Tests then get reported correctly on the project and build pages.