首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ScalaTest 3.0生成html报表

用ScalaTest 3.0生成html报表
EN

Stack Overflow用户
提问于 2019-11-27 04:51:38
回答 1查看 673关注 0票数 0

This question询问如何使用sbt和ScalaTest获取html报告。答案参考Scala test2.0,对于我的ScalaTest 3.0似乎不起作用

我通过以下方式声明ScalaTest:

代码语言:javascript
复制
    lazy val scalaTest = Seq("org.scalatest" %% "scalatest" % "3.0.8" % "test",
                             "org.scalactic" %% "scalactic" % "3.0.8",
                             "org.scalamock" %% "scalamock" % "4.4.0" % Test)

然后通过以下方式使用它

代码语言:javascript
复制
 ThisBuild / Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-h", "target/test-reports")

代码语言:javascript
复制
lazy val foo = (project in file("foo")).
    settings(libraryDependencies ++= scalaTest)

这将失败,原因是

代码语言:javascript
复制
[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)
...

这个问题建议使用"test->*"进行测试声明。正在尝试

代码语言:javascript
复制
    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
        )

取而代之的是失败

代码语言:javascript
复制
[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

随后出现的错误看起来像是FlatSpec的隐式转换不存在,并且可能是上述错误的后续错误。

有没有办法在ScalaTest 3.0中做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-27 05:11:36

尝试像这样添加pegdown依赖项

代码语言:javascript
复制
libraryDependencies += "org.pegdown" % "pegdown" % "1.6.0" % Test

注意:根据resolve #1201 replace pegdown with flexmark-java #1229,在ScalaTest 3.1.x中,pegdown被替换为flexmark-java

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59059164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档