我有一个Scala小项目,我正在用Gradle进行构建。我的IDE是Intellij Idea。我通过添加一个build.gradle
任务来配置spec
文件来运行测试,而无需在每个测试类上添加@RunWith(classOf[JUnitRunner])
批注,当我从命令行运行gradle时,它可以正常工作。
但是IDEA无法识别此任务,因此无法运行任何测试。当我尝试在IDEA中运行Test类时,出现错误No tests found for given includes:[chapter2.polymorphic.SequencesTest](filter.includeTestsMatching)
IDEA是否缺少一些根据build.gradle
文件运行测试的配置?
整个项目代码可在github
中找到下面是build.gradle
文件:
plugins {
id 'scala'
id 'java'
id 'idea'
}
apply plugin: 'scala'
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
}
wrapper {
gradleVersion = "5.4.1"
distributionType = Wrapper.DistributionType.ALL
}
def scalaVersion = "2.12"
dependencies {
compile "org.scala-lang:scala-library:${scalaVersion}.8"
// Use Scalatest for testing our library
testCompile 'junit:junit:4.12'
testCompile "org.scalatest:scalatest_${scalaVersion}:3.0.8"
// Need scala-xml at test runtime
testRuntime "org.scala-lang.modules:scala-xml_${scalaVersion}:1.2.0"
//html test reports
testCompile group: 'org.pegdown', name: 'pegdown', version: '1.6.0'
}
task spec(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', "build/classes/scala/test", '-o', '-h', 'build/tests/reports']
classpath = sourceSets.test.runtimeClasspath
}
test.dependsOn(spec)