Write Html Test Reports in ScalaTest While Retaining Console Output
If you are using ScalaTest with SBT and need to write out Html reports for your tests, add the following incantation to your build.sbt:
+= Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports") testOptions in Test
The above will write out Html reports to your target/test-reports directory.
Unfortunately this stops the writing of any test successes or failures to the console. You just get a message of the type: “x Tests Failed”. You have to then rummage around the Html reports to figure out what happened. Not ideal.
To get both the console output and the Html output for your tests, add the following incantation to your build.sbt:
++= Seq(Tests.Argument(TestFrameworks.ScalaTest, "-o"), Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports")) testOptions in Test
Read the full list of ScalaTest options for more configurations.
If you get the following NoClassDefFoundError error when generating reports:
[error] (test:executeTests) java.lang.NoClassDefFoundError: org/pegdown/PegDownProcessor
add the pegdown library to your dependencies:
"org.pegdown" % "pegdown" % "1.6.0" % "test"
Now you can have the best of both worlds!