Fake JUnit test result for Atlassian Bamboo's plan
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.

made it a “Final Task”,

and configured it as shown below:

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

And in case of failure:

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