Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I publish NUnit test results using Jenkins Pipeline?

Trying to use the nifty Jenkins Pipeline, I had problems finding out how to publish NUnit test results.

I am able to run the tests by specifying the following command in the pipeline script:

stage 'Test'
    bat '"C:\\Program Files (x86)\\NUnit 2.6.4\\bin\\nunit-console-x86.exe" "ProjectName\\bin\\Release\\UnitTests.net.dll"'

But how to make Jenkins "publish" the test results is not obvious. The Snippet Generator only suggests junit, and that does not seem to work.

like image 375
Ola Eldøy Avatar asked Nov 15 '16 11:11

Ola Eldøy


People also ask

How does Jenkins integrate with NUnit?

Add the NUnit Plugin to Jenkins. In your project go to Configure -> Build -> Add a build step. In the dropdown scroll down to -> Execute Windows Batch Command. Ensure this step is placed after your MSBuild step.

Which plugin can be used to create test results in HTML in Jenkins?

If you use the TestComplete Support plugin to run TestComplete tests with Jenkins, after the build run is over, the plugin will publish test results to Jenkins automatically. You can view them on the build results page.


2 Answers

I used nunit plugin version 0.21 and was able to publish results using

stage("PublishTestReport"){
     nunit testResultsPattern: 'TestResult.xml'
     }

(TestResult.xml is at the root of jenkins workspace in this above example)

like image 107
Sukhman Sandhu Avatar answered Sep 23 '22 17:09

Sukhman Sandhu


Investigating the NUnit plugin for Jenkins led me on to this issue, where I found the solution:

step([$class: 'NUnitPublisher', testResultsPattern: 'TestResult.xml', debug: false, 
                 keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])

Adding this to the pipeline script worked for me!

However, it seemed the following should also work (but at the present, apparently, it does not): Using the Snippet Generator, select this:

step: General Build Step
Publish NUnit test result report

This generates the following in the Pipeline script:

step <object of type hudson.plugins.nunit.NUnitPublisher>

This fails!

like image 24
Ola Eldøy Avatar answered Sep 19 '22 17:09

Ola Eldøy