繁体   English   中英

如何使用JUnit5在Gradle中编写Java集成测试任务?

[英]How to write a Java integration test task in Gradle with JUnit5?

使用Junit4,我对集成测试有以下定义:

task testIntegration(type: Test, dependsOn: jar) {
    group 'Verification'
    description 'Runs the integration tests.'
    testLogging {
        showStandardStreams = true
    }

    testClassesDirs = sourceSets.testInt.output.classesDirs
    classpath = sourceSets.testInt.runtimeClasspath
    systemProperties['jar.path'] = jar.archivePath
}

但是,对于JUnit5,这不再起作用。 我无法确定要更改的内容(为时已晚)。 有什么提示吗?

我正在使用junit-platform-gradle-plugin

我最终删除了插件并直接调用ConsoleRunner

task testIntegration(type: JavaExec, dependsOn: jar) {
    group 'Verification'
    description 'Runs the integration tests.'

    dependencies {
        testRuntime lib.junit5_console
    }

    classpath = sourceSets.testInt.runtimeClasspath
    systemProperties['jar.path'] = jar.archivePath

    main 'org.junit.platform.console.ConsoleLauncher'
    args = ['--scan-classpath', sourceSets.testInt.output.classesDirs.asPath,
            '--reports-dir', "${buildDir}/test-results/testInt"
    ]
}

另外,这是在设置中应用JaCoCo的方法:

afterEvaluate {
    jacoco {
        applyTo testUnit
        applyTo testIntegration
    }
    testIntegration.extensions.getByName("jacoco").excludes = ['*Test*', '*.?', '*Foo*', 'jodd.asm5.*', '*.fixtures.*']
}

有关更多详细信息,请检查Jodds构建文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM