u6f6o
u6f6o

Reputation: 2190

Why does the new gradle test filtering feature not work for my build script?

I am working on a "project" that has the following structure:

proj
  - dbfit-junit/module
    - db1
    - db2

To provide some background information: All of these "modules" (db1, db2) have JUnit tests that use the FitNesseRunner to integrate them in Bamboo.

My gradle script looks like following:

apply plugin: 'java'


repositories {
    mavenCentral()
}

dependencies {
    compile files(fileTree("lib"))
    testCompile "junit:junit:4.11"
}

ext {
    dbFitModuleDir = file("dbfit-junit/module")
    dbFitModules = dbFitModuleDir.listFiles({f -> f.isDirectory()} as java.io.FileFilter).collect{it.name}
}

dbFitModules.each { module ->
    sourceSets.create("${module}SourceSet") {
        java.srcDir new File(dbFitModuleDir, module)
        compileClasspath = sourceSets.main.output + configurations.testRuntime
        runtimeClasspath = output + sourceSets.main.output + configurations.testRuntime
    }

    task "dbFit${module.capitalize()}"(type: Test) {
        testClassesDir = sourceSets."${module}SourceSet".output.classesDir
        classpath = sourceSets."${module}SourceSet".runtimeClasspath
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}

So far everything works as expected and I am able to dynamically create the module specific gradle tasks and to execute the tests.

Nevertheless one thing is not working at all for me. I've learned from Gralde release notes 1.10 that there is a new feature called "test filtering" but it does not affect any of the tasks I am calling from commandline (e.g. gradlew dbFitDb1 --tests *DataIntegrity).

Although I apply the --tests filter all of my tests are executed. Thus I am wondering if there is sth. wrong with my script or if I have to enable test filtering in general etc.

Thx for any hints!

Upvotes: 3

Views: 2480

Answers (1)

u6f6o
u6f6o

Reputation: 2190

Found out that the filters do not work if you add a @RunWith annotation to your JUnit tests. The guys from Gradle aknowledged this issue and will fix it soon. In the meantime I'll use "test.single" to make it work.

https://issues.gradle.org/browse/GRADLE-3112

Upvotes: 2

Related Questions