Gaurav Gaurav - 24 days ago 18
Java Question

Gradle file is not running tests

I am trying to run my junit tests through gradle file but build gets successful but does not run any tests. This is how my gradle file looks like:

apply plugin: 'java'

// Creating a new sourceSet because you should move your integration tests to a separate directory.
sourceSets {
test {
java.srcDirs = ['src/integration-test/java']
}
integrationTest {
java.srcDirs = ['src/integration-test/java']
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}

configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}



task integrationTest(type: Test, description: 'Runs the integration tests', group: 'Verification') {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}


After running task integrationTest, build runs successfully but it does not run any tests. Does anyone know why?

Answer

Don't know what exactly you want to do: separate your integration tests of fully move test classes to other folder but I think you need to include the dependencies of test configuration like this:

configurations {
    integrationCompile.extendsFrom testCompile
    integrationRuntime.extendsFrom testRuntime
}

For example integration test configuration:

sourceSets {
    test {
        java.srcDirs = ['src/test/java']
    }
    integration {
        java.srcDirs = ['src/integration/java']
        resources.srcDir 'src/integration/resources'
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

configurations {
    integrationCompile.extendsFrom testCompile
    integrationRuntime.extendsFrom testRuntime
}

task integration(type: Test, group: 'Verification') {
    testClassesDir = sourceSets.integration.output.classesDir
    classpath = sourceSets.integration.runtimeClasspath
}
Comments