unbroken-dome / gradle-testsets-plugin

A plugin for the Gradle build system that allows specifying test sets (like integration or acceptance tests).
MIT License
230 stars 50 forks source link

Jacoco integration test report html not generating #122

Open ericus20 opened 3 years ago

ericus20 commented 3 years ago

I have a Java Spring Boot application that uses the testsets plugin with jacoco. I cannot get test coverage on integration test and have tried every example I have come across out there. I also posted the problem to stack overflow and yet to receive response.

https://stackoverflow.com/questions/68296588/jacoco-test-report-does-not-include-integrationtest

This is my entire build.gradle file.

import com.github.spotbugs.snom.SpotBugsTask

plugins {
    id 'org.springframework.boot' version '2.5.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'org.unbroken-dome.test-sets' version '4.0.0'
    id 'com.github.spotbugs' version '4.7.1'
    id 'checkstyle'
    id 'eclipse'
    id 'jacoco'
    id 'idea'
    id 'java'
    id 'pmd'
}

group = 'com.onlinebanking'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
targetCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

testSets {
    integrationTest
}

ext {
    mapstructVersion = '1.4.2.Final'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-mail'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-validation'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    implementation 'com.h2database:h2'
    runtimeOnly 'mysql:mysql-connector-java'

    //Java Faker
    implementation 'com.github.javafaker:javafaker:1.0.2'

    // Webjars
    implementation 'org.webjars:jquery:3.3.1'
    implementation 'org.webjars:bootstrap:4.1.3'
    implementation 'org.webjars:font-awesome:5.15.2'
    implementation 'org.webjars:popper.js:1.14.3'
    implementation 'org.webjars:bootbox:5.5.2'
    implementation 'org.webjars:datatables:1.10.24'
    implementation 'org.webjars:bootstrap-datetimepicker:6aa746736d'
    implementation 'org.webjars:webjars-locator:0.41'

    // MapStruct for Object Mapping
    implementation "org.mapstruct:mapstruct:${mapstructVersion}"
    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"

    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'

    // Testing
    testImplementation 'org.mockito:mockito-inline'
    testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.6.1'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

test {
    useJUnitPlatform()
}

// Checkstyle task to disable xml reports and load config file
tasks.withType(Checkstyle) {
    configFile file("${project.rootDir}/config/checkstyle.xml")
    include '**/*.java'
    exclude '**/gen/**'
    reports {
        xml.enabled = false
        html.enabled = true
    }

    classpath = files()
}

// SpotBugs task to disable xml reports and load config file
tasks.withType(SpotBugsTask) {
    reports {
        xml.enabled = false
        html.enabled = true
    }
}

pmd {
    ruleSetFiles = files("${project.rootDir}/config/pmd-ruleset.xml")
    ruleSets = []
}

jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                counter = 'LINE'
                value = 'COVEREDRATIO'
                minimum = 0.5
            }
        }
    }
}

test.finalizedBy jacocoTestReport // report is always generated after tests run
jacocoTestReport.dependsOn test // tests are required to run before generating the report
check.dependsOn integrationTest, jacocoTestCoverageVerification