我下载了Scala IDE Linux - 64 bit For Scala 2.11.2并尝试运行Scala测试。以下是我的代码。
package ppg.experiment.gameofbusiness.engine
import org.scalatest.FlatSpec
import org.scalatest.Matchers
class DiceSpec extends FlatSpec with Matchers {
"A dice" should "roll a value greater than zero" in {
new Dice().roll > 0
}
it should "roll a value less than six" in {
new Dice().roll < 7
}
}
当我右键单击并以Scala Test身份运行时,控制台上会打印以下内容
WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all uses of -p to -R.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:58)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
Caused by: java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
at org.scalatest.tools.Runner$.argTooShort$1(Runner.scala:1515)
at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1532)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:923)
at org.scalatest.tools.Runner$.main(Runner.scala:860)
at org.scalatest.tools.Runner.main(Runner.scala)
... 6 more
有人可以告诉我如何解决这个问题吗?
答案 0 :(得分:6)
检查你的类路径;特别要检查scalalatest的版本是否依赖于为scala 2.11而不是2.10编译。