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:

testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports")

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:

testOptions in Test ++= Seq(Tests.Argument(TestFrameworks.ScalaTest, "-o"), Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports"))

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!