Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins and JUnit

I've read over the Jenkins site and its JUnit plugin, and for some reason something that is very basic is just not apparent to me.

Jenkins has an Email-ext plugin for sending custom/advanced notification emails whenever a build is ran. In these emails you can place "content tokens" that are runtime variables that get replaced with dynamic values when the email is being generated.

One of these tokens is TEST_COUNTS which allows you to display the number of JUnit tests that ran, or which failed, etc.

How does one go about getting Jenkins to display this information correctly? Is there a plugin I need, and if so, which one? I have my build running JUnit and generating an XML report. I assume Jenkins somehow parses JUnit results out of that XML and uses it to give values to that token.

But on the other hand, I've read "literature" (mailing list posts) that seems to suggest that in order to use that token you need to use Jenkins to run the unit tests, not a junit Ant task from inside your build script.

Can someone clarify this for me and perhaps even set out the "order of operations" for what steps I need to take in order to be able to make use of this token?

It would be supremely useful to get test counts in our build notifications.

like image 380
IAmYourFaja Avatar asked Jan 09 '12 14:01

IAmYourFaja


2 Answers

Your first explanation is right. You tell Jenkins where to search for JUnit output files, and it parses them to find out the test results:

Screenshot of the Jenkins configuration

The test results appear on each project and build page, so as long as you're seeing the correct results there, you should get the correct token replacements in your e-mails

like image 57
Michael Mrozek Avatar answered Oct 20 '22 17:10

Michael Mrozek


Add something like this to the content in the "Editable Email Notification" configuration:

Total = $TEST_COUNTS
Failed = ${TEST_COUNTS,var="fail"}

I also recommend the Jenkins users mailing list for Jenkins questions, usually helpful.

like image 28
oeuftete Avatar answered Oct 20 '22 18:10

oeuftete