Prettier HTML Reports for Cucumber-JVM
I work a fair bit with Cucumber-JVM in my professional life, which runs various acceptance / component tests for Java services. When sharing test results with stakeholders such as Product Owners, I need an easier format to share with them, so have used the built-in Cucumber html
reporting:
Late last year, Tim Norris recommended I try out the Jenkins plugin cucumber-reports-plugin
for reporting instead of the built-in HTML reporter. He's been using it for some of the services that he owns, and found that the use of the plugin made looking at test results much easier than using the built-in reporting, not least because it was a bit more visual in its usage.
As we can see, it has a much nicer visual breakdown of the steps and features:
All the plugin needs is to be pointed to your cucumber-report.json
, after which it'll publish the HTML to the Jenkins UI.
However, the issue with this plugin is that it does this purely through Jenkins, not through the actual Cucumber test run. This means that in your i.e. target/
directory after a local build you won't get these pretty HTML reports, nor will you be able to easily download them through the Jenkins UI.
As I started to write a feature request on the cucumber-reporting
project, which is the core library that cucumber-reports-plugin
uses, I realised I should be a good Open Source citizen and take a look at the code first.
I couldn't seem to find anything that implemented the Cucumber Formatter
, which would allow me hook it into the @CucumberOptions
like so:
@CucumberOptions(plugin = {"pretty", "json:target/report.json", "cucumber-reporting:target/pretty-cucumber"}, features = {"classpath:features"})
But searching through the issues on the repo led me to the issue Is it possible to use cucumber-reporting plugin through cucumber CLI Runner? in which GitHub user monochromata mentioned that they had written cucumber-reporting-plugin
to handle this.
This means it's really easy to run:
@CucumberOptions(plugin = {"pretty", "json:target/report.json", "de.monochromata.cucumber.report.PrettyReports:target/pretty-cucumber"}, features = {"classpath:features"})
Now, running Cucumber will generate a pretty report, which we can then view locally or archive within Jenkins, which look pretty great.
This saved me having to write my own wrapper to handle this, so thanks for the work on it! Hopefully it'll make it upstream to cucumber-reporting
soon.
Update: The library is now deprecated, but I've forked it to me.jvt.cucumber:reporting-plugin
, and am seeking my fork becoming the official successor.
Update 2020-01-26: For a clear example of how to add the reporting plugin to your project, including adding the dependency, please see this example Merge Request.