sbt 上的 ScalaTest 没有运行任何测试 [英] ScalaTest on sbt not running any tests
问题描述
我正在尝试使用以下命令运行我的测试:sbt 然后测试.
I am trying to run my tests with: sbt and then test.
我的 build.sbt 看起来像这样
My build.sbt looks like this
lazy val scalatest = "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test"
lazy val root = (project in file(".")).
settings(
name := "highlight2pdf",
version := "0.1",
scalaVersion := "2.11.6",
libraryDependencies += scalatest
)
我只是将示例测试放在 test/scala 上
And i just put the example test on test/scala
import collection.mutable.Stack
import org.scalatest._
class ExampleSpec extends FlatSpec with Matchers {
"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should be (2)
stack.pop() should be (1)
}
it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[Int]
a [NoSuchElementException] should be thrownBy {
emptyStack.pop()
}
}
}
仍然总是显示:
[信息] 未执行任何测试.
[info] No tests were executed.
有没有想过为什么它不起作用?
Any thoughts on why it's not working?
推荐答案
默认情况下,目录结构不是 sbt
查找 ExampleSpec.scala
的正确约定.
The directory structure isn't the correct convention for sbt
to find ExampleSpec.scala
by default.
├── built.sbt
├── src
│ └── test
│ └── scala
│ ├── ExampleSpec.scala
将其更改为上面的结构并在顶级目录中运行 sbt test
,它应该可以工作.同样,scala 源代码会进入 src/main/scala
并被编译.
Change it to the structure above and run sbt test
in the top level directory and it should work. Likewise, scala source would go in src/main/scala
and would get compiled.
> test
[info] Compiling 1 Scala source to /tmp/TestsWontRun/target/scala-2.11/test-classes...
[info] ExampleSpec:
[info] A Stack
[info] - should pop values in last-in-first-out order
[info] - should throw NoSuchElementException if an empty stack is popped
[info] Run completed in 289 milliseconds.
[info] Total number of tests run: 2
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 7 s, completed Apr 30, 2015 8:54:30 AM
这篇关于sbt 上的 ScalaTest 没有运行任何测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!