我的目录结构是:
|/src
| |/main
| | |/com.episo
| | | |/contracts
| | | | |/clip
| | | | |/security
| | | |/repositories
| | | | |/memory
| |/test
| | |/com.episo
| | | |/contracts
| | | | |/clip
| | | | |/security
| | | |/repositories
| | | | |/memory
这是我的 build.gradle 的相关部分:
repositories {
mavenCentral()
maven { url "http://dl.bintray.com/jetbrains/spek" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile 'com.google.guava:guava:19.0'
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile 'com.google.guava:guava:19.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile 'org.junit.platform:junit-platform-runner:1.0.0-M4'
testCompile 'org.junit.platform:junit-platform-console:1.0.0-M4'
testCompile ('org.jetbrains.spek:spek-api:1.1.2') {
exclude group: 'org.jetbrains.kotlin'
}
testRuntime ('org.jetbrains.spek:spek-junit-platform-engine:1.1.2') {
exclude group: 'org.junit.platform'
exclude group: 'org.jetbrains.kotlin'
}
}
// JaCoCo coverage rules
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.5
}
}
rule {
element = 'PACKAGE'
limit {
counter = 'CLASS'
value = 'COVEREDRATIO'
minimum = 0.7
}
}
}
}
junitPlatform {
filters {
engines {
include 'spek'
}
}
enableStandardTestTask true
}
我的代码是用 Kotlin 编写的,并且我正在使用 Spek 编写我的单元测试。当我通过 IntelliJ GUI 运行测试时,会正确报告代码覆盖率。但是,当我运行时gradle jacocoTestCoverageVerification
,我得到以下输出:
* What went wrong:
Execution failed for task ':jacocoTestCoverageVerification'.
> Rule violated for bundle episo-contracts: instructions covered ratio is 0.2, but expected minimum is 0.5
Rule violated for package com.episo.contracts: classes covered ratio is 0.0, but expected minimum is 0.7
Rule violated for package com.episo.repositories: classes covered ratio is 0.0, but expected minimum is 0.7
Rule violated for package com.episo.contracts.security: classes covered ratio is 0.0, but expected minimum is 0.7
显然,包裹的 0.0 覆盖率是不正确的;这意味着我没有编写任何测试,事实并非如此。
我的目录结构是否有可能使 Jacoco 无法了解哪些测试与哪些类匹配?