Posted on by & filed under java, programming, Tech, testing.

A few months ago I noticed the JUnit Attachments Plugin and was inspired.  Recording pictures and other files after test failures is such an obviously good idea, especially if you’re the one who has to fix the tests.

Unfortunately, the JUnit Attachments Plugin has some rough edges. I wrote a small library that handles the busywork while keeping tests readable.  Since we are awesome, we open sourced it so you can use it too!

This post assumes you already use Jenkins for continuous integration for your Java projects.  If you don’t, and would like to get started with Jenkins, I strongly recommend Jenkins: The Definitive Guide.  The book is an excellent resource, even for experienced Jenkins users. (Do you want to send your office into red alert on build failure? or hook Jenkins up to a rabbit?)

 1000 words

Configure Jenkins

To use the Jenkins Helper, first configure your Jenkins instance to use the JUnit Attachments Plugin:

  • Go to (where “” is the URL to your Jenkins instance)
  • Under the “Available” tab, select “JUnit Attachments Plugin”
  • Click “Download now and install after restart”
  • Restart Jenkins.


Configure your build

Then configure your Jenkins build to use the Plugin.

  • Click the “Configure” link in your project
  • Under “Post-build Actions” select “Add post-build action” and add  “Archive the artifacts” if you have not already
  • For “Files to archive”, add “target/test-attachments/**”
  • Again if you have not already added “Publish JUnit test result report,” add it with “Add post-build action”
  • Select the “Publish test attachments” checkbox

Configure your Project

This example assumes a Java-based project.

Include jenkins-helper-java in your pom as a test dependency

You will need to include RecordAttachmentRule as a rule in your junit test

Annotate your Tests

Then annotate public fields or methods you would like recorded on test failure

The interface is simple: artifacts will only be recorded on test failure, and nothing will be recorded if they are null.

Like most web development shops, we use Selenium WebDriver for much of our automated testing.  It’s easy to take a picture and capture the DOM when a test fails.

Now whenever your WebDriver test fails, Jenkins will link to a picture of the failure.

Checkout the source.

Tags: continuous integration, java, jenkins, programming, Selenium, testing,

Comments are closed.