簡體   English   中英

ScalaTest沒有運行任何測試

[英]ScalaTest on sbt not running any tests

我正在嘗試運行我的測試: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
)

我只是將示例測試放在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]沒有執行任何測試。

為什么它不起作用的任何想法?

目錄結構是不正確的約定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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM