Intellij Idea 2019.1.3无法运行ScalaTests

时间:2019-06-23 14:45:48

标签: scala gradle intellij-idea scalatest

我有一个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)



0 个答案:

没有答案