【发布时间】:2015-06-27 14:16:06
【问题描述】:
我的任务是在 Scala Play 中更新和编写一系列应用程序测试,这是一种我不熟悉的语言和框架。我想做的一部分是集成 ScalaTestPlus 库。为了开始,我一直在学习以下教程:
https://www.playframework.com/documentation/2.2.x/ScalaTestingWithScalaTest
不幸的是,我没有走得太远。我在测试文件夹中添加了一个新的单元测试文件:
import org.scalatestplus.play._
class StackSpec extends PlaySpec {
"A Test" must {
"pass" in {
assert(1 == 1)
}
"Fail" in {
assert(1 != 1)
}
}
}
我已经更新了我的 build.sbt 以包含 scalatestplus 库
"org.scalatestplus" % "play_2.37" % "1.2.0" % "test"//,
使用 Activator,我正在尝试使用仅测试运行我的测试文件。一切都编译没有错误,但激活器没有找到任何测试
[info] No tests were executed.
我不认为问题出在激活器上,因为我可以使用 test 和 test-only 命令运行旧的测试文件(来自以前的工程师)。先前(工作)测试文件之一的快速示例:
import java.util.concurrent.TimeUnit
import com.sun.xml.internal.bind.v2.TODO
import scala.collection.JavaConverters._
import controllers.Application
import models.{Item, PriorityBucket}
import play.api.test._
class WebSpec extends PlaySpecification {
"Home page" should {
"do something" in new WithSeleniumDbData(TestUtil.testApp) {
Redacted.deleteAll()
val ObId = TestUtil.create(Some(PriorityBucket.Low),
Some(Application.ENGLISH))
val item = Item.find(ItemId).get
browser.goTo("/")
browser.await().atMost(2,
TimeUnit.SECONDS).until(Selectors.all_obs).isPresent
}
有什么想法让我误入歧途了吗?提前感谢您的帮助!
我正在使用 scala 2.11 我正在使用 play 2.3.7
编辑:可能相关,我将扩展从 PlaySpec 切换到 FlatSpec 并在编译时看到以下错误:
SampleSpec.scala:10: value in is not a member of String
[error] "pass" in {
我确保也导入了 FlatSpec,这让我有点困惑——FlatSpec 是 ScalaTest 的成员但不是 ScalaTestPlus 的成员,我不明白为什么编译会失败。
更新:为了进一步调查这个问题,我开发了一个全新的 Play 应用并复制了我的示例测试。在使用版本进行一些工具之后,我已经能够让我的测试与套件的其余部分一起在 activator test 命令上运行。不幸的是,像 test-only 这样的任何其他命令仍然没有返回任何测试运行。
【问题讨论】:
-
尝试
import org.junit.runner._并将@RunWith(classOf[JUnitRunner])添加到班级 -
不幸的是没有工作。当我导入 org.junit.runner.RunWith 并导入 org.scalatest.junit.JUnitRunner 时,结果相同
标签: scala playframework scalatest