当在一个模块中添加测试用例时,Sonarqube 不会拾取其他测试用例

问题描述

我正在开发一个多模块 Gradle 项目,其中应用程序 Web、业务、持久性、通用和外部有五个模块

项目结构如下

enter image description here

这是父应用程序中的 Gradle 构建文件

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'org.sonarqube' version '2.7'
}

group = 'com.financemanagement'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }

    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}



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

allprojects{
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    apply plugin: 'java'
    apply plugin: 'org.sonarqube'
    apply plugin: 'project-report'
    apply plugin: 'jacoco'

    repositories {
        mavenCentral()
        mavenLocal()
        maven { url 'https://repo.spring.io/milestone' }
    }

    //  jacoco {
    //      toolVersion = "0.7.9"
    //      reportsDir = file("$buildDir/customJacocoReportDir")
    //  }

    dependencies{

        implementation 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'

        implementation 'org.springframework.boot:spring-boot-starter'
        
        implementation 'org.springframework.boot:spring-boot-starter-web'
        
        testImplementation 'org.springframework.boot:spring-boot-starter-test'

        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

        // https://mvnrepository.com/artifact/org.assertj/assertj-core
        testCompile group: 'org.assertj',name: 'assertj-core',version: '3.12.2'

        // https://mvnrepository.com/artifact/com.openpojo/openpojo
        testCompile group: 'com.openpojo',name: 'openpojo',version: '0.8.13'

        // https://mvnrepository.com/artifact/com.openpojo/openpojo
        compile group: 'com.openpojo',version: '0.8.13'
        
        // https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
        compile group: 'org.apache.commons',name: 'commons-lang3',version: '3.10'
        
        // https://mvnrepository.com/artifact/commons-io/commons-io
        compile group: 'commons-io',name: 'commons-io',version: '2.6'
        
        // https://mvnrepository.com/artifact/org.apache.commons/commons-collections4
        compile group: 'org.apache.commons',name: 'commons-collections4',version: '4.4'
        
        // https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter
        compile group: 'io.springfox',name: 'springfox-boot-starter',version: '3.0.0'
        
        // https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui
        compile group: 'io.springfox',name: 'springfox-swagger-ui',version: '3.0.0'
    }


    test {
        reports.junitXml.destination = file("$rootProject.buildDir/reports/xml")
        reports.html.destination = file("$rootProject.buildDir/reports/html")
        //systemProperty 'spring.profiles.active','test'
    }


    sonarqube {
        properties {
            property "sonar.sourceEncoding","UTF-8"
            property "sonar.host.url","http://localhost:9000"
            property "sonar.projectKey","com.financemanagement:fm-category-management"
            property "sonar.projectName","fm-category-management"
            property "sonar.projectVersion","0.0.1-SNAPSHOT"
            property 'sonar.java.coveragePlugin',"jacoco"
        }
    }

}

dependencies {
    compile project(":fm-category-management-business")
    compile project(":fm-category-management-web")
    compile project(":fm-category-management-persistence")
    compile project(":fm-category-management-common")
    compile project(":fm-category-management-external")

    implementation 'org.springframework.boot:spring-boot-starter-actuator'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

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

test {
    useJUnitPlatform()
}


htmlDependencyReport {
    reports.html.destination = file("build/reports/project/dependencies")
}

不寻常的是,在我将测试用例添加到 Web 模块之前,我的声纳报告正确地显示了测试用例的数量和覆盖率,如下所示

enter image description here

但是在我在 web 模块中添加测试用例之后,

enter image description here

sonarqube 报告仅显示 Web 模块中的测试用例数量并相应地计算覆盖率。

enter image description here

Web 模块测试用例包括一些 @WebMvcTest 和一些其他通用 Junit。

我不明白我在这里做错了什么。任何帮助将不胜感激。

谢谢...!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)