11

The way to do this for specs2 based test in sbt is

(testOptions in Test) += Tests.Argument(TestFrameworks.Specs2, "html")

but how about scalatest? I've done lots of Google search, but cannot find a good explanation/solution.

Sheng
  • 1,697
  • 4
  • 19
  • 33

3 Answers3

9

so two things I need to do...

I. use any scalatest artifact after 2.0.M5b. For me, I added this dependency,

org.scalatest" %% "scalatest" % "2.0.M6" % "test->*" excludeAll ( ExclusionRule(organization="org.junit", name="junit") )

"test->*" is necessary, otherwise dependencies needed to generate the html wont be downloaded. (There must be a better way than this)

II. In build.sbt, add

(testOptions in Test) += Tests.Argument(TestFrameworks.ScalaTest, "-u", "target/report")

Sheng
  • 1,697
  • 4
  • 19
  • 33
  • 2
    This should be -h for html reporting. -u is xml reporting. – NKijak Aug 12 '14 at 18:45
  • 1
    This does not work with Scalatest 3.0.7: `Symbol 'type org.scalactic.TripleEquals' is missing from the classpath.` It also complains about `Tolerance` and `term org.scalactic.source`. Any idea how to update this for 3.0? – Troy Daniels Nov 26 '19 at 20:20
5

beware with that setting.

org.scalatest" %% "scalatest" % "2.0.M6" % "test->*

It pulls out some junit:junit:3.8.1 dependency which ivy fails to resolve. see this bug

this is a better way to do it in ScalaTest 2.0

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

This works well in Jenkins

fracca
  • 2,417
  • 1
  • 23
  • 22
0

Here is how I do it. Change your build.sbt in this way:

Test/testOptions := Seq(
  Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/scalatest")
),
projectDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "3.2.9" //% Test,
  "com.vladsch.flexmark" % "flexmark" % "0.36.8" % Test,
  "com.vladsch.flexmark" % "flexmark-profile-pegdown" % "0.36.8" % Test,
  ...
)

The flexmark dependency isn't documented but it is necessary. An HTML report will be generated in the target/scalatest directory. You can publish it with Jenkins. I've tested with more recent versions of flexmark, but it doesn't work.

david.perez
  • 6,090
  • 4
  • 34
  • 57