使用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 build file

07-26 08:44