JaCoCo报道未在报告中显示,但在intellij中有效

时间:2020-08-03 07:48:56

标签: java spring-boot junit junit5 jacoco

我一直试图找出问题所在,因为我为控制器类编写了一个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**'
            ])
        }))
    }
}

0 个答案:

没有答案