我正在运行Scala 2.10.3
和sbt 0.13.5
,并且松散地关注Twitter的scala sbt tutorial我遇到了一个小问题。单元测试根本不会运行。
我的build.sbt:
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.1.7" % "test"
我的考试班:
package com.twitter.sample
import collection.mutable.Stack
import org.scalatest._
object SimpleParserSpec extends FlatSpec with Matchers {
"SimpleParser" should "work with basic tweet" in {
val parser = new SimpleParser
val tweet = """{"id":1, "text":"foo"}"""
parser.parse(tweet) match {
case Some(parsed) => {
parsed.text should be ("foo")
parsed.id should be (1)
}
case _ => fail("didn't parse tweet")
}
}
}
这是项目文件夹中运行sbt test
的输出:
[info] Loading global plugins from C:\Users\Slench\.sbt\0.13\plugins
[info] Set current project to twitter-sbt (in build file:/C:/Users/Slench/Desktop/twitter-sbt/)
[info] Run completed in 36 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[success] Total time: 0 s, completed 05-06-2014 20:19:11
我不确定出了什么问题,所有文件都在正确的文件夹中,所有文件都编译没有错误或警告,但它不会运行我的测试......有什么帮助吗?
答案 0 :(得分:5)
将SimpleParserSpec
从object
更改为class
,它应该有效。
特别是改变行
//bad
object SimpleParserSpec extends FlatSpec with Matchers
到
//good
class SimpleParserSpec extends FlatSpec with Matchers