我正在尝试使用ScalaJS和SBT。 SBT正在编译文件,并且uTest正在运行,但它只是忽略了我的测试。尽可能地尝试我在代码和教程示例之间找不到任何区别。
build.sbt:
enablePlugins(ScalaJSPlugin)
name := "Scala.js Stuff"
scalaVersion := "2.11.5" // or any other Scala version >= 2.10.2
scalaJSStage in Global := FastOptStage
libraryDependencies += "com.lihaoyi" %% "utest" % "0.3.0"
testFrameworks += new TestFramework("utest.runner.Framework")
的src /测试/阶/ COM / mysite的/木星/ GeometryTest.scala:
package com.mysite.jovian
import utest._
object GeometryTest extends TestSuite {
def tests = TestSuite {
'addPoints {
val p: Point = new Point(3,4)
val q: Point = new Point(4,3)
val expected: Point = new Point(8,8)
assert(p.plus(q).equals(expected))
throw new Exception("foo")
}
'fail {
assert(1==2)
}
}
}
输出:
> reload
[info] Loading project definition from /Users/me/Dropbox (Personal)/mysite/flocks/project
[info] Set current project to Scala.js Stuff (in build file:/Users/me/Dropbox%20(Personal)/mysite/flocks/)
> test
[success] Total time: 1 s, completed Mar 6, 2015 7:01:41 AM
> test-only -- com.mysite.jovian.GeometryTest
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for test:testOnly
[success] Total time: 1 s, completed Mar 6, 2015 7:01:49 AM
如果我引入语法错误,sbt test确实会看到它:
> test
[info] Compiling 1 Scala source to /Users/me/Dropbox (Personal)/mysite/flocks/target/scala-2.11/test-classes...
[error] /Users/me/Dropbox (Personal)/mysite/flocks/src/test/scala/com/mysite/jovian/GeometryTest.scala:21: not found: value blablablablabla
[error] blablablablabla
[error] ^
[error] one error found
[error] (test:compile) Compilation failed
[error] Total time: 1 s, completed Mar 6, 2015 7:03:54 AM
所以它肯定会看到代码,它似乎并不认为“测试”包含任何测试。
否则,在非测试代码中,SBT + ScalaJS似乎工作正常......
感谢您的帮助,我感到很困惑。
答案 0 :(得分:7)
你的错误在于对uTest的依赖:
libraryDependencies += "com.lihaoyi" %% "utest" % "0.3.0"
这是JVM依赖项。要使用启用了Scala.js的依赖项,请使用%%%
而不是%%
,如下所示:
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0"
此外,您可能只希望在Test配置中使用此依赖项,因此在结尾处添加% "test"
:
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0" % "test"