无法让 uTest 查看我的测试

Cannot get uTest to see my tests

我正在尝试让 uTest 与 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/test/scala/com/mysite/jovian/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
[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

所以它肯定是看到了代码,它似乎不认为 "tests" 包含任何测试。

否则,在非测试代码中,SBT+ScalaJS 似乎工作正常...

谢谢大家的帮助,我一头雾水

你的错误在于对uTest的依赖:

libraryDependencies += "com.lihaoyi" %% "utest" % "0.3.0"

这是一个 JVM 依赖项。要使用启用 Scala.js 的依赖项,请使用 %%% 而不是 %%,如下所示:

libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0"

此外,您可能只希望在测试配置中使用此依赖项,因此在末尾添加 % "test"

libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0" % "test"