I am currently experiencing a strange effect when using the MStest plugin. My test report is only generated when the test is successful but when it fails, no test report is generated. Thanks to this answer, Jenkins integration for dotnet test my pipeline looks like this
node {
stage('Checkout') {
cleanWs()
checkout scm
return
skipRemainingStages = true
}
stage('Restore') {
sh "dotnet restore $project1"
}
stage('Build') {
sh "dotnet publish $project1 --output $outputFolder --configuration Release -p:Version=$buildVersion -p:FileVersion=$buildVersion"
}
stage ('Unit test') {
sh "dotnet restore $UnitTest"
sh returnStdout: true, script: "dotnet test $UnitTest --logger \'trx;LogFileName=unit_tests.xml\' "
step ([$class: 'MSTestPublisher', testResultsFile:"**/*.xml", failOnError: true, keepLongStdio: true])
}
}
The log:
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Results File: /var/jenkins_home/workspace/myproject/Build_master/myproject/TestResults/unit_tests.xml
Total tests: 16. Passed: 8. Failed: 8. Skipped: 0.
Test Run Failed.
Test execution time: 15.9443 Seconds
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE
I do not know why test reports are not generated when test fails. Thanks enter image description here