Gradle仅对主模块进行单元测试(使用Junit:4.11)(gradle多模块项目)

发布于 2025-01-11 10:13:14 字数 2860 浏览 0 评论 0原文

我目前正在构建一个项目,该项目依赖于我从 github 获得的另一个项目,但单元测试仅针对新创建的模块运行,有关如何让单元测试在整个项目中运行的任何提示吗?

当我 gradle test 时,我仅获得新模块的测试,当我 gradle :module2:test 时,我得到 Junit 成功测试了零测试。

架构

->new module (called app)
     ->build.gradle (call it 1- )
->github module (called module2)
     ->build.gradle (call it 2- )
     ->settings.gradle
->settings.gradle

Build.gradle 1-

    plugins {
    id 'rss.java-application-conventions'
    id 'idea'
    id 'com.adarshr.test-logger' version '3.2.0'
}

sourceCompatibility = 1.8
repositories { jcenter() }

dependencies {
    implementation project(':xmlrss')
    implementation 'org.apache.commons:commons-text'
    testImplementation 'junit:junit:4.11'
    implementation 'junit:junit:4.11'
}

repositories {
    gradlePluginPortal() // so that external plugins can be resolved in dependencies section
    mavenCentral()
}

version = '0.1.0'

application {
    // Define the main class for the application.
    mainClass = 'rss.app.App'
}
jar {
    manifest {
        attributes 'Main-Class': 'rss.app.MainClass'
    }
}


test {
    dependsOn(':module2:test')
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "short"

        // set options for log level DEBUG
        debug {
            events "started", "skipped", "failed"
            exceptionFormat "full"
        }

        // remove standard output/error logging from --info builds
        // by assigning only 'failed' and 'skipped' events
        info.events = ["failed", "skipped"]
    }
}

Build.gradle 2-

    plugins {
    id 'rss.java-library-conventions'
    id 'idea'
    id 'com.adarshr.test-logger' version '3.2.0'
}
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation group: 'org.apache.santuario', name: 'xmlsec', version: '2.0.8'
    testImplementation 'junit:junit:4.11'
    implementation 'junit:junit:4.11'
}

repositories {
    gradlePluginPortal() // so that external plugins can be resolved in dependencies section
    mavenCentral()
}


test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "short"

        // set options for log level DEBUG
        debug {
            events "started", "skipped", "failed"
            exceptionFormat "full"
        }

        // remove standard output/error logging from --info builds
        // by assigning only 'failed' and 'skipped' events
        info.events = ["failed", "skipped"]
    }
}

Settings.gradle(对于 module2):

rootProject.name = 'module2'

Settings.gradle(在根文件夹中):

rootProject.name = 'rss'
include('app', 'module2')

I'm currently building a project that depends on another that I got from github, but the unit tests only run for the newly created module, any hints on how to get the unit tests to run in the whole project?

When I gradle test I get only the tests for the new module and when I gradle :module2:test I get that Junit successfully tested zero tests.

Architecture

->new module (called app)
     ->build.gradle (call it 1- )
->github module (called module2)
     ->build.gradle (call it 2- )
     ->settings.gradle
->settings.gradle

Build.gradle 1-

    plugins {
    id 'rss.java-application-conventions'
    id 'idea'
    id 'com.adarshr.test-logger' version '3.2.0'
}

sourceCompatibility = 1.8
repositories { jcenter() }

dependencies {
    implementation project(':xmlrss')
    implementation 'org.apache.commons:commons-text'
    testImplementation 'junit:junit:4.11'
    implementation 'junit:junit:4.11'
}

repositories {
    gradlePluginPortal() // so that external plugins can be resolved in dependencies section
    mavenCentral()
}

version = '0.1.0'

application {
    // Define the main class for the application.
    mainClass = 'rss.app.App'
}
jar {
    manifest {
        attributes 'Main-Class': 'rss.app.MainClass'
    }
}


test {
    dependsOn(':module2:test')
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "short"

        // set options for log level DEBUG
        debug {
            events "started", "skipped", "failed"
            exceptionFormat "full"
        }

        // remove standard output/error logging from --info builds
        // by assigning only 'failed' and 'skipped' events
        info.events = ["failed", "skipped"]
    }
}

Build.gradle 2-

    plugins {
    id 'rss.java-library-conventions'
    id 'idea'
    id 'com.adarshr.test-logger' version '3.2.0'
}
sourceCompatibility = 1.8

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation group: 'org.apache.santuario', name: 'xmlsec', version: '2.0.8'
    testImplementation 'junit:junit:4.11'
    implementation 'junit:junit:4.11'
}

repositories {
    gradlePluginPortal() // so that external plugins can be resolved in dependencies section
    mavenCentral()
}


test {
    useJUnitPlatform()
    testLogging {
        events "passed", "skipped", "failed"
        exceptionFormat "short"

        // set options for log level DEBUG
        debug {
            events "started", "skipped", "failed"
            exceptionFormat "full"
        }

        // remove standard output/error logging from --info builds
        // by assigning only 'failed' and 'skipped' events
        info.events = ["failed", "skipped"]
    }
}

Settings.gradle (for module2):

rootProject.name = 'module2'

Settings.gradle (in root folder):

rootProject.name = 'rss'
include('app', 'module2')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文