Покрытие JaCoCo не отображается в отчете, но работает в intellij - PullRequest
0 голосов
/ 03 августа 2020

Я пытался выяснить, в чем проблема: я написал тестовые примеры junit для класса контроллера, но jacoco не показывает покрытие для него, когда я вижу окончательный отчет, он показывает нулевое покрытие, но для всех остальных такие классы, как класс обслуживания, показывают покрытие. Я использую команду gradle: "gradle clean build jacocoTestReport" нужно ли мне что-либо менять в файле build.gradle для конфигурации jacoco.

ниже находится файл build.gradle

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    id 'jacoco'
    id "org.sonarqube" version "2.7"
}

group = 'com.abc.abcd.abcde'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '8.0'

repositories {
    mavenCentral()
}

ext {
    set('springCloudVersion', "Hoxton.SR3")
}

configurations.all {
      exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    runtime group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: "${springCloudVersion}"
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    implementation('org.springframework.boot:spring-boot-starter-web') {
       exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'  
    }     
    implementation('org.springframework.boot:spring-boot-starter-log4j2')
    implementation('com.microsoft.azure:azure-storage:8.4.0')
    compile group: 'com.googlecode.juniversalchardet', name: 'juniversalchardet', version: '1.0.3'
    testImplementation('org.junit.jupiter:junit-jupiter:5.4.0')
    testImplementation 'org.mockito:mockito-inline:2.13.0'
    implementation 'junit:junit:4.12'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

test {
    minHeapSize = "128m"
    maxHeapSize = "2280m"
    useJUnitPlatform()
    afterTest { desc, result -> 
        logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
    }
}

jacoco {
    toolVersion = "0.8.5"
}

jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
        html.enabled true
    }
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                                        'com/abc/abcd/abcde/files/FilesApplication*',
                                        'com/abc/abcd/abcde/files/entity',
                                        'com/abc/abcd/segmentation/files/exception',
                                        'com/abc/abcd/segmentation/files/response/FileInfo*',
                                        'com/abc/abcd/segmentation/files/dto**'
            ])
        }))
    }
}
...