2014-06-29 9 views
7

Ho iniziato a utilizzare ScalaTest con sbt. Il build.sbt è la seguente:Perché sbt dice "cattivo riferimento simbolico ..." per il test con ScalaTest?

name := "MySpecSample" 

version := "1.0" 

libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.0" % "test" 

scalaVersion := "2.10.3" 

codice di prova iniziale è qui. Questo codice di test funziona da solo senza codice componente principale.

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

L'ho scritto secondo Official quick start. Ma non funziona correttamente. Il messaggio di errore è il seguente:

> test 
[info] Compiling 1 Scala source to /Users/kaisasak/untitled/target/scala-2.10/test-classes... 
[error] bad symbolic reference. A signature in package.class refers to type compileTimeOnly 
[error] in package scala.annotation which is not available. 
[error] It may be completely missing from the current classpath, or the version on 
[error] the classpath might be incompatible with the version used when compiling package.class. 
[error] /Users/kaisasak/untitled/src/test/scala/ExampleSpec.scala:6: Reference to class FlatSpec in package scalatest should not have survived past type checking, 
[error] it should have been processed and eliminated during expansion of an enclosing macro. 
[error] class ExampleSpec extends FlatSpec with Matchers { 
[error]      ^
[error] two errors found 
[error] (test:compile) Compilation failed 
[error] Total time: 3 s, completed Jun 29, 2014 11:20:41 AM 

Posso trovare gli stessi problemi su Google ma nessuna risposta valida era disponibile. Il mio ambiente è qui.

  • MacOSX 10.9.3
  • Scala 2.10.3
  • SBT 0.13.2

Ho provato con SBT 0.13.1 dopo declassamento, ma il risultato è lo stesso di quello di 0.13.2. Cosa devo fare per usare ScalaTest con sbt?

risposta

17

Nella tua build.sbt si imposta la versione di Scala alla 2.10.3 con il seguente:

scalaVersion := "2.10.3" 

Tuttavia la dipendenza ScalaTest utilizza Scala 2.11 esplicitamente (si noti la parte _2.11):

"org.scalatest" % "scalatest_2.11" % "2.2.0" % "test" 

Devi usare la stessa versione di scala maggiore per entrambi.

con SBT si può semplicemente garantire ciò utilizzando %% invece di % come segue:

"org.scalatest" %% "scalatest" % "2.2.0" % "test" 
+0

Questo problema è stato risolto in base al vostro consiglio. Grazie! –

Problemi correlati