Reputation: 1370
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?
Upvotes: 2
Views: 6426
Reputation: 131
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
}
In case if you just want to move your tests in other folder(src/integration-test/java
) and run them with test
task you can use the following configuration:
sourceSets {
test {
java.srcDirs = ['src/integration-test/java']
}
}
Upvotes: 2