scalatest not working in intellij 13.1
I can't seem to get Intellij 13.1 to run my tests. I've created a simple project to try and isolate the problem but it is also not working there. Here is my setup:
Here is the sut:
object Calc {
def add(a: Int, b: Int) = {
a + b
}
}
Here is the test:
import org.scalatest.FunSuite
class Calc$Test extends FunSuite {
test("two number should add") {
assert(Calc.add(2, 5) == 7)
}
}
This is the error I am getting:
Error:scalac: while compiling: /Users/test-user/Development/temp/sample/src/test/scala/Calc$Test.scala during phase: typer library version: version 2.10.4 compiler version: version 2.10.4 reconstructed args: -nobootcp -javabootclasspath : -classpath /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/deploy.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/dt.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/javaws.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/jconsole.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/management-agent.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/plugin.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/sa-jdi.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar:/System/Library/Java/Jav aVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/apple_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/dnsns.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/localedata.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunjce_provider.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext/sunpkcs11.jar:/Users/test-user/Development/temp/sample/target/scala-2.10/test-classes:/Users/test-user/Development/temp/sample/target/scala-2.10/classes:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-library.jar:/Users/test-user/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.2.jar:/Users/test-user/.ivy2/cache/org.scala-lang/scala-reflect/ja rs/scala-reflect-2.11.2.jar:/Users/test-user/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.2.jar:/Users/test-user/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.1.jar:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-reflect.jar:/Users/test-user/.sbt/boot/scala-2.10.4/lib/scala-compiler.jar last tree to typer: Apply(method ==) symbol: method == in class Int (flags: ) symbol definition: def ==(x: Int): Boolean tpe: Boolean symbol owners: method == -> class Int -> package scala context owners: value -> class Calc$Test -> package == Enclosing template or block == Template( // val : in class Calc$Test "FunSuite" // parents ValDef( private "_" ) // 2 statements DefDef( // def (): Calc$Test in class Calc$Test "" [] List(Nil) // tree.tpe=Calc$Test Block( // tree.tpe=Unit Apply( // def (): org.scalatest.FunSuite in class FunSuite, tree.tpe=org.scalatest.FunSuite Calc$Test.super."" // def (): org.scalatest.FunSuite in class FunSuite, tree.tpe= ()org.scalatest.FunSuite Nil ) () ) ) Apply( Apply( "test" "two number should add" ) Apply( "assert" Apply( // def ==(x: Int): Boolean in class Int, tree.tpe=Boolean Calc.add(2, 5)."$eq$eq" // def ==(x: Int): Boolean in class Int, tree.tpe=(x: Int)Boolean 7 ) ) ) ) == Expanded type of tree == TypeRef(TypeSymbol(final abstract class Boolean extends AnyVal)) uncaught exception during compilation: scala.MatchError
Any idea what the issue might be? I assume this is caused by a simple config problem as the code is about as simple as can be.
One problem you clearly have is that you're asking for the version of scalatest compiled for Scala 2.11, but you say you're using Scala 2.10. You need "scalatest_2.10" instead of "scalatest_2.11" in your build.sbt. Use
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.2.1" % "test"
or perhaps even
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.1" % "test"
to get your Scala version picked up automatically (note the change to to a double percent: %%.)
Since your project is 2.10 backed, use the same version for scalatest too,
scalaVersion := "2.10.5" // don't need to mention scalatest_2.10, will be reflected automatically
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" // works with 2.2.1 or 3.0.0
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
Or using maven,
<dependency>
<groupId>org.scalactic</groupId>
<artifactId>scalactic_2.10</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
Reference here http://www.scalatest.org/install
链接地址: http://www.djcxy.com/p/62784.html上一篇: 像树结构一样计算树中的图层