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

若如初见. 提交于 2019-12-23 19:17:30

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/21020841/why-does-the-new-gradle-test-filtering-feature-not-work-for-my-build-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!