task scalaTest(dependsOn: testClasses) << {
description = 'Runs Scalatest suite'
ant.taskdef(name: 'scalatest',
classname: 'org.scalatest.tools.ScalaTestAntTask',
classpath: sourceSets.test.runtimeClasspath.asPath
)
ant.scalatest(runpath: sourceSets.test.output.classesDir,
haltonfailure: 'true', fork: 'false') {
reporter(type: 'stdout')
}
}我运行gradle scalaTest,然后得到:
* What went wrong:
Execution failed for task ':scalaTest'.
> java.lang.NoClassDefFoundError: scala/reflect/ClassManifest$我使用的是Scala 2.10.2和Gradle 1.7
dependencies {
compile 'org.scala-lang:scala-library:2.10.2'
testCompile 'org.scalatest:scalatest:1.3'
testCompile 'org.scalamock:scalamock_2.10:3.0.1'
}怎么了??
发布于 2013-09-16 17:10:51
我不知道如何解决这个问题,但我可以为您提供一个变通方法。使用@RunWith(classOf[JUnitRunner])注释您的测试类,如下所示:
import org.scalatest.junit.JUnitRunner
import org.junit.runner.RunWith
@RunWith(classOf[JUnitRunner])
class MyTest extends FunSpec{
}然后,gradle test应该可以工作了。
编辑:
我的依赖项:
compile "org.scala-lang:scala-library:2.10.1"
testCompile "org.scalatest:scalatest_2.10:1.9.1"发布于 2014-11-24 08:57:00
您可以在build.gradle中添加以下内容
task spec(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o']
classpath = sourceSets.test.runtimeClasspath
}注意:的路径可能会因gradle版本的不同而不同,正如@MikeRylander在评论中指出的那样。在gradle 4之前,它通常是“build/classes/test”。
然后只需运行gradle spec来执行您的测试。我将任务命名为spec,因为已经有一个test任务。我不知道您是否可以覆盖默认的测试任务。
您可以查找可用的选项here。
发布于 2019-06-27 23:54:32
此响应可能会有点晚。但是对于使用scala和gradle (5.x)的人来说,下面的方法是可行的。
将以下插件添加到gradle中。
plugins {
id "com.github.maiflai.scalatest" version "0.25"
}运行代码
> gradle test作为奖励,来自上述plugin的测试结果也将比默认报告报告得更好。
https://stackoverflow.com/questions/18823855
复制相似问题