2015-04-30 51 views
6

我想运行我的测试: sbt然后测试。ScalaTest on sbt没有运行任何测试

我build.sbt看起来像这样

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 
) 

,我只是把示例测试上测试/斯卡拉

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() 
      } 
     } 
    } 

不过它总是显示:

[信息]没有测试被执行。

任何方式它不工作?

回答

7

默认情况下,目录结构不是sbt找到ExampleSpec.scala的正确惯例。

├── built.sbt 
├── src 
│   └── test 
│    └── scala 
│     ├── ExampleSpec.scala 

它更改为上述的结构和运行顶级目录sbt test,它应该工作。同样,scala源将会在src/main/scala中进行编译。

> 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