PDStat
PDStat

Reputation: 5855

Gradle integration test building but not running

I'm setting up a multi module gradle project and trying to separate integration tests for all subprojects. I've managed to create integTest task and I can see it builds the integration test classes and creates integration test reports in different directories to the unit tests. It isn't however running my integration test.

Project structure is something like

|_ gradle
| |_ integration-test.gradle
|_ subproject
| |_ src
| |  |_ main
| |  | |_ java
| |  | |_ resources
| |  |_ test
| |  | |_ java
| |  | |_ resources
| |  |_ integTest
| |    |_ java
| |    | |_sit
| |    |   |_ MyTest.java
| |    |_ resources
| |_ build.gradle
|_ build.gradle
|_ gradle.properties
|_ settings.gradle

In the integration-test.gradle I have

sourceSets {
    integTest {
        java.srcDir file('src/integTest/java')
        resources.srcDir file('src/integTest/resources')
        compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
        runtimeClasspath += output + compileClasspath
    }
}

dependencies {
    integTestCompile sourceSets.main.output
    integTestCompile sourceSets.test.output 

    integTestCompile configurations.compile
    integTestCompile configurations.testCompile 

    integTestRuntime configurations.runtime
    integTestRuntime configurations.testRuntime 
}

task integTest(type: Test) {
    group = LifecycleBasePlugin.VERIFICATION_GROUP
    description = 'Runs the integration tests.' 

    maxHeapSize = '1024m' 

    testClassesDir = sourceSets.integTest.output.classesDir
    classpath = sourceSets.integTest.runtimeClasspath 

    binResultsDir = file("$buildDir/integration-test-results/binary/integTest")

    reports { 
        html.destination = "$buildDir/reports/integration-test"
        junitXml.destination = "$buildDir/integration-test-results"
    }

    mustRunAfter tasks.test
}

check.dependsOn integTest

And then in the subproject build.gradle I add the following at the top

apply from: "$rootDir/gradle/integration-test.gradle"

After running gradle clean build I can see the unit tests building and running and see the test reports afterwards. I can also see that the integration tests are building in a separate integTest directory underneath the classes in the build dir. I can also see a new integration-test-results directory created in the build directory, however the tests defined in MyTest.java are not running

I also see this in the console when running with the -i flag

> Task :javaproject:integTest
Task ':javaproject:integTest' is not up-to-date because:
  Output property 'binResultsDir' file E:\dev\java\workspace\javaproject\subproject\build\integration-test-results\binary\integTest has been removed.
  Output property 'binResultsDir' file E:\dev\java\workspace\javaproject\subproject\build\integration-test-results\binary\integTest\output.bin has been removed.
  Output property 'binResultsDir' file E:\dev\java\workspace\javaproject\subproject\build\integration-test-results\binary\integTest\output.bin.idx has been removed.
Finished generating test XML results (0.0 secs) into: E:\dev\java\workspace\javaproject\subproject\build\integration-test-results
Generating HTML test report...
Finished generating test html results (0.006 secs) into: E:\dev\java\workspace\javaproject\subproject\build\reports\integration-test
:javaproject:integTest (Thread[Task worker for ':',5,main]) completed. Took 0.092 secs.
:javaproject:check (Thread[Task worker for ':',5,main]) started.

Upvotes: 9

Views: 6398

Answers (1)

PDStat
PDStat

Reputation: 5855

Right for anyone using JUnit5 and setting up integration tests in this way make sure to add useJUnitPlatform() to your integration test task. So my task became

task integTest(type: Test) {
    useJUnitPlatform()
    group = LifecycleBasePlugin.VERIFICATION_GROUP
    description = 'Runs the integration tests.' 

    maxHeapSize = '1024m' 

    testClassesDir = sourceSets.integTest.output.classesDir
    classpath = sourceSets.integTest.runtimeClasspath 

    binResultsDir = file("$buildDir/integration-test-results/binary/integTest")

    reports { 
        html.destination = "$buildDir/reports/integration-test"
        junitXml.destination = "$buildDir/integration-test-results"
    }

    mustRunAfter tasks.test
}

And then it all started magically working. I spotted it because I re-ran the build with gradle clean build -d and spotted the following which helped me refine my googlefu

13:58:08.909 [DEBUG] [TestEventLogger] Gradle Test Run :subproject:integTest STARTED
13:58:08.943 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector] test-class-scan : failed to scan parent class java/lang/Object, could not find the class file

Upvotes: 27

Related Questions