我是scala的新手,我正在尝试几个示例代码进行测试。但是,当我运行测试代码时,我遇到了一些问题。当我运行测试时,我收到错误
[trace] Stack trace suppressed: run last test:executeTests for the full output.
[error] (test:executeTests) java.lang.NoClassDefFoundError: scala/Product$class
[error] Total time: 3 s, completed Feb 27, 2017 6:57:15 PM
我的代码如下
FilterChecks.scala
class filterChecks extends FlatSpec {
"Filter checker passed a filename which is present in directory" should "return file name" in {
val matchingFileName = new FileObject("match")
val listOfFiles = List(new FileObject("random"), matchingFileName)
val matchedFiles = new FilterChecker("match").findMatchedFiles(listOfFiles)
assert(matchedFiles == List(matchingFileName))
}
}
FilterChecker类
class FilterChecker(filter : String) {
def matches(content : String) = content.contains(filter);
def findMatchedFiles(fileObjects : List[FileObject]) = {
for(fileObject <- fileObjects if(matches(fileObject.name)))
yield fileObject
}
}
FileObject
class FileObject(val name: String) {
}
构建文件如下:
name := "testScalaProject"
version := "1.0"
scalaVersion := "2.12.1"
// https://mvnrepository.com/artifact/org.scala-js/scalajs-test-interface_2.12
libraryDependencies ++= Seq("org.scala-js" % "scalajs-test-interface_2.12" % "0.6.14",
"org.scalatest" % "scalatest_2.11" % "2.2.5",
"com.novocode" % "junit-interface" % "0.11",
"org.scala-lang" % "scala-library" % "2.12.1")
有人可以帮助我找到问题。提前致谢
答案 0 :(得分:31)
你的sbt构建文件不对。您的scala版本是2.12.x但您使用的是scala版本2.11中编译的库。使用下面显示的sbt设置
注意:我更改了scalatest的版本,因为2.12版本的scala不再支持2.x版本
scalaVersion := "2.12.1"
libraryDependencies ++= Seq(
"org.scala-js" %% "scalajs-test-interface" % "0.6.14",
"org.scalatest" %% "scalatest" % "3.0.1", //version changed as these the only versions supported by 2.12
"com.novocode" % "junit-interface" % "0.11",
"org.scala-lang" % "scala-library" % scalaVersion.value
)
记得在sbt控制台中执行reload
,clean
和compile
以开始清理编译