简体   繁体   中英

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

With Junit4, I had the following definition of integration test:

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
}

However, with JUnit5, this does not work anymore. I am not being able to figure what to change (it's too late). Any hints?

I am using the junit-platform-gradle-plugin .

I ended up removing the plugin and calling ConsoleRunner directly:

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"
    ]
}

Also, here is how to apply JaCoCo with the settings:

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

FOr more details check Jodds build file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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