gpt4 book ai didi

scala - 无法让 uTest 查看我的测试

转载 作者:行者123 更新时间:2023-12-04 18:05:41 25 4
gpt4 key购买 nike

我试图让 uTest 与 ScalaJS 和 SBT 一起工作。 SBT 正在编译文件,并且 uTest 正在运行,但它只是忽略了我的测试。尽我所能,我找不到我的代码和教程示例之间的任何区别。

构建.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 确实会看到它:
> 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 似乎工作正常......

感谢您的帮助,我很困惑。

最佳答案

你的错误在于对 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"

关于scala - 无法让 uTest 查看我的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28898445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com