Fake JUnit test result for Atlassian Bamboo's plan

⚠️ Please note: The information in this legacy post may no longer be relevant.

Hi! Today I going to share with you a little trick, which I used once for one of my Atlassian Bamboo’s plans. First, Bamboo is a continuous integration server developed by Atlassian. (off topic*: This is a holy war’s subject, but Bamboo is a Jenkins’ competitor). Anyway, I had to make a check of some parameter after build’s finish. The build was always successful, so Bamboo always mark it as “green”. My goal was to set it “red” if some metrics valuse wasn’t good enough. And after a conversation with my skilled colleagues I found a solution.

JUnit parser

So, the idea was clear. I just needed to create fake test result for my Bamboo’s Job! At first, I created a templates like the one below, for “good” case scenario:

<?xml version='1.0' encoding='utf-8'?>
<testsuite errors="0" failures="0" disabled="0" name="Name for a plan" tests="1" time="1"><testcase name="case name" status="run" time="0" errors="0"></testcase></testsuite>

And for bad case scenario:

<?xml version='1.0' encoding='utf-8'?>
<testsuite errors="1" failures="0" disabled="0" name="Name for a plan" tests="1" time="1"><testcase name="case name" status="run" time="0" errors="1"><error file="related file" line="1" message="Your message, that will be shown on Tests tab in bamboo's plan details." /></testcase></testsuite>

As you see, the difference is in errors=" statements and in <testcase> tags.

After that, I set up a simple check using a “script” task in Bamboo. This script generates a file named fakereport.xml - one version if the check passes, and a different version (with the same filename) if it fails. The details of the checker are beyond the scope of this post, but it’s quite straightforward. Once that was in place, I added a JUnit task.

Junit Parser task

made it a “Final Task”,

Junit Parser task 2

and configured it as shown below:

Junit Parser task 3

And that’s it! Now when my check is OK, I get a result like this:

Junit Parser task 4

And in case of failure:

Junit Parser task 5

I agree, that’s not the designed way to use the JUnit parser in any sense, more like a little trick.

Written on August 18, 2017