0

This question asks how to get an html report with sbt and ScalaTest. The answers reference Scala test 2.0 and do not appear to work for me with ScalaTest 3.0

I declare ScalaTest by

    lazy val scalaTest = Seq("org.scalatest" %% "scalatest" % "3.0.8" % "test",
                             "org.scalactic" %% "scalactic" % "3.0.8",
                             "org.scalamock" %% "scalamock" % "4.4.0" % Test)

and then use it by

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

and

lazy val foo = (project in file("foo")).
    settings(libraryDependencies ++= scalaTest)

This fails with

[error] java.lang.NoClassDefFoundError: org/pegdown/PegDownProcessor
[error]     at org.scalatest.tools.HtmlReporter.<init>(HtmlReporter.scala:117)
[error]     at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:192)
[error]     at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:239)
[error]     at org.scalatest.tools.ReporterFactory.$anonfun$createReportersFromConfigurations$1(ReporterFactory.scala:248)
[error]     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:237)
[error]     at scala.collection.Iterator.foreach(Iterator.scala:941)
[error]     at scala.collection.Iterator.foreach$(Iterator.scala:941)
[error]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
[error]     at scala.collection.IterableLike.foreach(IterableLike.scala:74)
[error]     at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
[error]     at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:42)
...

The question suggests using "test->*" for the test declaration. Trying

    lazy val scalaTest = Seq("org.scalatest" %% "scalatest" % "3.0.8" % "test->*" excludeAll (
                                 ExclusionRule(organization="org.junit", name="junit")),
                             "org.scalamock" %% "scalamock" % "4.4.0" % Test
        )

instead fails with

[info] Compiling 1 Scala source to /projects/foo/target/scala-2.12/test-classes ...
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:17:73: Symbol 'type org.scalactic.TripleEquals' is missing from the classpath.
[error] This symbol is required by 'trait org.scalatest.Assertions'.
[error] Make sure that type TripleEquals is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Assertions.class' was compiled against an incompatible version of org.scalactic.
[error] class InfoGainTest extends FlatSpec with Matchers with LoneElement with LazyLogging {
[error]                                                                         ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:17:42: Symbol 'type org.scalactic.Tolerance' is missing from the classpath.
[error] This symbol is required by 'trait org.scalatest.Matchers'.
[error] Make sure that type Tolerance is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Matchers.class' was compiled against an incompatible version of org.scalactic.
[error] class InfoGainTest extends FlatSpec with Matchers with LoneElement with LazyLogging {
[error]                                          ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:22:54: Symbol 'term org.scalactic.source' is missing from the classpath.
[error] This symbol is required by 'value org.scalatest.Matchers.pos'.
[error] Make sure that term source is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Matchers.class' was compiled against an incompatible version of org.scalactic.
[error]     def printGain(gainByProbe: Map[Probe, Double]) = logger.info("Info gain: {}",
[error]                                                      ^
[error] /projects/foo/src/test/scala/com/example/FooTest.scala:27:17: value should is not a member of String

followed by errors that look like the implicit conversions for FlatSpec are not present and are probably follow-on errors from the above.

Is there a way to do this with ScalaTest 3.0?

Troy Daniels
  • 3,270
  • 2
  • 25
  • 57

1 Answers1

2

Try adding pegdown dependency like so

libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0" % Test

Note in ScalaTest 3.1.x pegdown is replaced with flexmark-java as per resolve #1201 replace pegdown with flexmark-java #1229

Mario Galic
  • 47,285
  • 6
  • 56
  • 98