调用ScalaTest时出现java.lang.reflect.InvocationTargetException

时间:2014-07-01 12:17:15

标签: scala scalatest

无法找到此堆栈跟踪的解决方案我将回答此问题,因此可能对其他人有用。

尝试运行ScalaTest文件时:

import org.scalatest.FlatSpec

class DataTest extends FlatSpec {

  "Number of Links" should "be" in {

    assert(2 === 2)

  }

}

我收到此例外:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:22)
    at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
Caused by: java.lang.NoSuchMethodError: scala.collection.IterableLike.elements()Lscala/collection/Iterator;
    at org.scalatest.tools.Runner$.checkArgsForValidity(Runner.scala:611)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:500)
    at org.scalatest.tools.Runner$.main(Runner.scala:476)
    at org.scalatest.tools.Runner.main(Runner.scala)
    ... 6 more

问题是什么?

1 个答案:

答案 0 :(得分:0)

问题是ScalaTest的版本。项目正在使用:

<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest</artifactId>
    <version>1.3</version>
</dependency> 

但需要

<dependency>
    <groupId>org.scalatest</groupId>
    <artifactId>scalatest_2.10</artifactId>
    <version>2.2.0</version>
</dependency>