简体   繁体   English

Jacoco在我的Gradle项目中未显示Spock代码覆盖率

[英]Jacoco not showing Spock code coverage in my Gradle project

I have a Gradle project configured with jacoco plugin to report the test code coverage. 我有一个配置了jacoco插件的Gradle项目来报告测试代码覆盖率。 My unit tests are written in Spock framework. 我的单元测试是用Spock框架编写的。

Though the Jacoco plugin generates the HTML report, it reports the code coverage as 0% on all classes. 尽管Jacoco插件生成了HTML报告,但它报告所有类的代码覆盖率为0%。

I googled a lot and couldn't find what I'm missing. 我在Google上搜索了很多,找不到我想要的东西。 Has anyone got the Spock code coverage working with Gradle + Jacoco? 有没有人与Gradle + Jacoco合作使用Spock代码?

apply plugin: "jacoco"
apply plugin: "groovy"

sourceSets {
    main {
        java { srcDirs = ['src/main/java'] }
        groovy {srcDirs = ['src/main/groovy'] }
        resources { srcDir 'src/main/resources' }
    }

    test {
        java { srcDirs = ['src/test/java'] }
        groovy { srcDirs = ['src/test/groovy'] }
        resources { srcDir 'src/test/resources' }
    }
}

test {
    jvmArgs '-Xms64m', '-Xmx2G', '-XX:MaxPermSize=128m'
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/jacocoHtml"
    }
}

dependencies {
    testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
    testCompile "org.spockframework:spock-spring:0.7-groovy-2.0"
}

Suggestion from @PeterNiederwieser worked perfectly. @PeterNiederwieser的建议非常有效。 Here is the final result: 这是最终结果:

apply plugin: "groovy"
apply plugin: "jacoco"

repositories { mavenCentral() }

dependencies {
  compile "org.codehaus.groovy:groovy-all:2.2.2"
  testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}

jacocoTestReport {
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "${buildDir}/jacocoHtml"
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM