无法让 uTest 查看我的测试 [英] Cannot get uTest to see my tests

查看:53
本文介绍了无法让 uTest 查看我的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get uTest to work with ScalaJS and SBT. SBT is compiling the files, and uTest is running, but it simply ignores my tests. Try as I might I cannot find any difference between my code and the tutorial examples.

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:

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 确实会看到:

If I introduce a syntax error, sbt test does see it:

> 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

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

So it's definitely seeing the code, it just doesn't seem to think that "tests" contains any tests.

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

Otherwise, in the non-test code, SBT+ScalaJS seems to be working fine...

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

Thanks for any help, I am mystified.

推荐答案

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

Your mistake lies in the dependency on uTest:

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

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

This is a JVM dependency. To use the Scala.js-enabled dependency, use %%% instead of %%, like this:

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

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

Additionally, you probably want this dependency only in the Test configuration, so add % "test" a the end:

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

这篇关于无法让 uTest 查看我的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆