问题描述
我有以下课程:
import scala.util.{Success, Failure, Try}
class MyClass {
def openFile(fileName: String): Try[String] = {
Failure( new Exception("some message"))
}
def main(args: Array[String]): Unit = {
openFile(args.head)
}
}
其中有以下单元测试:
class MyClassTest extends org.scalatest.FunSuite {
test("pass inexistent file name") {
val myClass = new MyClass()
assert(myClass.openFile("./noFile").failed.get.getMessage == "Invalid file name")
}
}
当我运行 sbt test
时,出现以下错误:
When I run sbt test
I get the following error:
java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
at org.scalatest.tools.FriendlyParamsTranslator$.translateArguments(FriendlyParamsTranslator.scala:174)
at org.scalatest.tools.Framework.runner(Framework.scala:918)
at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:533)
at sbt.Defaults$$anonfun$createTestRunners$1.apply(Defaults.scala:527)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.Map$Map1.foreach(Map.scala:109)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at sbt.Defaults$.createTestRunners(Defaults.scala:527)
at sbt.Defaults$.allTestGroupsTask(Defaults.scala:543)
at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:410)
at sbt.Defaults$$anonfun$testTasks$4.apply(Defaults.scala:410)
at scala.Function8$$anonfun$tupled$1.apply(Function8.scala:35)
at scala.Function8$$anonfun$tupled$1.apply(Function8.scala:34)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (test:executeTests) java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
构建定义:
version := "1.0"
scalaVersion := "2.12.0"
// https://mvnrepository.com/artifact/org.scalatest/scalatest_2.11
libraryDependencies += "org.scalatest" % "scalatest_2.11" % "3.0.0"
我无法弄清楚是什么导致了这种情况.我的课程和单元测试看起来很简单.有什么想法吗?
I can't figure out what causes this. My class and unit test seem simple enough. Any ideas?
推荐答案
scalatest_2.11
是仅与 Scala 2.11.x 兼容的 ScalaTest 版本.写 libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
(注意 %%
) 来自动选择正确的版本并切换到 Scala 2.11.8,直到 scalatest_2.12
发布(应该很快).请参阅 http://www.scala-sbt.org/0.13/docs/Cross-Build.html 了解更多.
scalatest_2.11
is the version of ScalaTest compatible only with Scala 2.11.x. Write libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test"
(note %%
) instead to pick the correct version automatically and switch to Scala 2.11.8 until scalatest_2.12
is released (it should be very soon). See http://www.scala-sbt.org/0.13/docs/Cross-Build.html for more.
这篇关于java.lang.NoSuchMethodError: scala.Predef$.refArrayOps的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!