2015-04-30 11 views
6

Sto tentando di eseguire i miei test con: sbt e quindi test.ScalaTest su sbt non esegue alcun test

mio build.sbt assomiglia a questo

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 
) 

E ho appena messo alla prova esempio sulla 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() 
      } 
     } 
    } 

Ancora mostrano sempre:

[info] Nessun test sono stati giustiziati

Qualsiasi ostacolo sulla strada non funziona?

risposta

7

La struttura di directory non è la convenzione corretta per sbt per trovare ExampleSpec.scala per impostazione predefinita.

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

Modifica alla struttura di cui sopra ed eseguire sbt test nella directory di livello superiore e dovrebbe funzionare. Allo stesso modo, la sorgente di scala andrebbe in src/main/scala e verrebbe compilata.

> 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 
Problemi correlati