Generate HTML report for JGiven with SBT

465 Views Asked by At

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.

2

There are 2 best solutions below

0
Clément HELIOU On BEST ANSWER

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
0
Jan Schaefer On

I do not know SBT in detail, however, as @ahus1 already mentions in his comment, you can just call the com.tngtech.jgiven.report.ReportGenerator main class. For example:

build.sbt:

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

On the command line:

$ sbt
> run-main com.tngtech.jgiven.report.ReportGenerator --sourceDir=target/jgiven-reports/json/ --targetDir=target/jgiven-reports/html

It would be great if you could tell me if your final solution, so that I can document it in the JGiven documentation.