1

My directory structure is:

|/src
|   |/main
|   |  |/com.episo
|   |  |  |/contracts
|   |  |  |  |/clip
|   |  |  |  |/security
|   |  |  |/repositories
|   |  |  |  |/memory
|   |/test
|   |  |/com.episo
|   |  |  |/contracts
|   |  |  |  |/clip
|   |  |  |  |/security
|   |  |  |/repositories
|   |  |  |  |/memory

And here is the relevant section of my 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
}

My code is written in Kotlin, and I am using Spek to write my unit tests. When I run my tests through the IntelliJ GUI, code coverage is properly reported. However, when I run gradle jacocoTestCoverageVerification, I get the following output:

* 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

Obviously, the 0.0 covered ratio for the packages is not correct; that would mean I haven't written any tests, which is not the case at all.

Is there maybe something about my directory structure that is making Jacoco not pick up on which tests match with which classes?

Mat Jones
  • 936
  • 1
  • 10
  • 27
  • If you run `gradle test` do your tests run? – jrtapsell Sep 08 '17 at 06:32
  • @jrtapsell yes `gradle test` runs all of my tests – Mat Jones Sep 11 '17 at 15:52
  • Is this any help? > https://stackoverflow.com/questions/45464138/jacoco-returning-0-coverage-with-kotlin-and-android-3-0 – jrtapsell Sep 11 '17 at 16:05
  • @jrtapsell I came across that question in my initial search for a solution, but it doesn't seem to be relevant to our project. Also, if we run the tests through IntelliJ with coverage, it reports near 100% coverage. – Mat Jones Sep 11 '17 at 16:29

0 Answers0