问题描述
我正在研究一个具有以下结构的项目:
proj
- dbfit-junit / module
- db1
- db2
提供一些背景信息:全部这些模块(db1,db2)具有使用FitNesseRunner将它们集成到Bamboo中的JUnit测试。
我的gradle脚本如下所示:
apply plugin:' java'
存储库{
mavenCentral()
}
依赖关系{
编译文件(fileTree(lib ))
testCompilejunit:junit:4.11
}
$ b $ 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
}
任务dbFit $ {module.capitalize()}(type:Test){
testClassesDir = sourceSets。$ {module} SourceSet.output.classesDir $ b $ classpath class = sourceSets。$ {module} SourceSet.runtimeClasspath
}
}
任务包装器(type:Wrapper){
gradleVersion ='1.10'
}
远远一切都按预期工作,我能够动态地创建模块特定的gradle任务并执行测试。
然而有一件事对我来说根本就不起作用。我从有一个称为测试过滤的新功能,但它不影响我从命令行调用的任何任务(例如,gradlew dbFitDb1 --tests * DataIntegrity)。
尽管我应用了--tests筛选器,我的所有测试都已执行。因此,我想知道是否有某事。
Thx任何提示!
发现如果您将@RunWith注释添加到JUnit测试中,则过滤器不起作用。 Gradle的人认识到了这个问题,并且很快就会解决它。在此期间,我将使用test.single来使其工作。
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!
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
这篇关于为什么新的gradle测试过滤功能不适用于我的构建脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!