sbt为什么不运行ScalaTest的示例测试?

时间:2019-12-01 20:15:40

标签: scala testing sbt scala.js

请假定使用正常的“新手”应用。

我正在使用Scala 2.12.10;在build.sbt中,我添加了ScalaTest:

libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"

我正在向现有的Java项目中添加一些scala.js,因此我的scala源路径​​是正常的,但是我为Java和资源创建了一些空目录,并使用了不同的目标,因此不会与现有代码发生冲突:

javaSource in Compile := baseDirectory.value / "src/main/scalajs_java"
javaSource in Test := baseDirectory.value / "src/test/scalajs_java"

resourceDirectory in Compile := baseDirectory.value / "src/main/scalajs_resources"
resourceDirectory in Test := baseDirectory.value / "src/test/scalajs_resources"

target := baseDirectory.value / "scalajs_target"

我将ScalaTest示例文件ExampleSpec.scala放在src / test / scala / ExampleSpec.scala中。如http://www.scalatest.org/中所述,使用org.scalatest.run可以很好地运行该示例。

我认为测试类路径看起来很合理

sbt:RedsPro-ScalaJS> show test:fullClasspath
[info] * Attributed(/Users/tballard/git/redspro/reds/scalajs_target/scala-2.12/test-classes)
[info] * Attributed(/Users/tballard/git/redspro/reds/scalajs_target/scala-2.12/classes)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.12.10.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-js/scalajs-library_2.12/jars/scalajs-library_2.12-0.6.31.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-js/scalajs-dom_sjs0.6_2.12/jars/scalajs-dom_sjs0.6_2.12-0.9.7.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-js/scalajs-test-bridge_2.12/jars/scalajs-test-bridge_2.12-0.6.31.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-js/scalajs-test-interface_2.12/jars/scalajs-test-interface_2.12-0.6.31.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scalatest/scalatest_2.12/bundles/scalatest_2.12-3.0.8.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scalactic/scalactic_2.12/bundles/scalactic_2.12-3.0.8.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.12.10.jar)
[info] * Attributed(/Users/tballard/.ivy2/cache/org.scala-lang.modules/scala-xml_2.12/bundles/scala-xml_2.12-1.2.0.jar)

编译后,测试就是我期望的位置:

> ls scalajs_target/scala-2.12/test-classes/
ExampleSpec.class   ExampleSpec.sjsir   JS_DEPENDENCIES     org/

但是,sbt显然不相信会有任何测试:

sbt:RedsPro-ScalaJS>  show definedTestNames
[info] *
[success] Total time: 1 s, completed Dec 1, 2019, 11:37:51 AM

sbt:RedsPro-ScalaJS> testOnly ExampleSpec
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for Test / testOnly
[success] Total time: 1 s, completed Dec 1, 2019, 12:44:35 PM

朝正确方向的一点将不胜感激。

1 个答案:

答案 0 :(得分:2)

取决于ScalaTest时,您需要使用%%%而不是%%。通常,您总是需要在Scala.js中使用%%%