Search code examples
playframeworksbtbddplayframework-2.3jgiven

Generate HTML report for JGiven with SBT


I am using JGiven for my tests in one of my Play 2.3.x application. The documentation explains how to generate HTML reports for Maven and Gradle. But nothing is available for SBT.

Is there any workaround to generate reports at the end of the tests ? Maybe by adding something in build.sbt ? I tried to play with "javaOptions in Tests" but couldn't figure out how to make it work.

Thanks.


Solution

  • See below my solution using a dedicated SBT task.

    1. First add the jgiven-html5-report dependency:

    libraryDependencies += "com.tngtech.jgiven" % "jgiven-html5-report" % "0.15.3" % "test"

    1. Then declare a new task. Let's call it livingDocumentation:

    lazy val livingDocumentation = taskKey[Unit]("Generate HTML5 JGiven report") livingDocumentation := Def.sequential( test in Test, runMain in Test toTask " com.tngtech.jgiven.report.ReportGenerator" ).value

    Using Def.sequential, I can chain 2 tasks and ensure the source JSON reports are available.

    1. Finally, run the SBT task using sbt livingDocumentation