Test filtering does not work

Gradle Version: 2.3
OS: Mac OS X 10.11 and CentOS 6.x, JVM 1.7

We run a test task with the following arguments:

test -x testClasses -x compileJava -x processResources -x classes -x compileTestJava -x processTestResources --tests XXX

Whether XXX is valid or not, Gradle proceeds to run all tests it can find in a project.

Hi Vladimir,

Unfortunately, I cannot reproduce this issue in a simple project. Neither with 2.3 nor 3.1 (which is the latest version).

Can you share more details about the structure of your project (are you using subprojects?) and a Build Scan?

You can also check if using a newer Gradle version resolves your problem.

Thank you for looking into this, Jendirk.

I’ve tried with Gradle 2.9 - same problem (couldn’t go to 3.1 because it does not recognize testSrcDirs property).

The link to Build Scan is: https://gradle.com/s/wwjy5qwowiaja. I used --tests OOO - clearly invalid, but the scan shows that Gradle ran 100+ tests.

The project does not have any sub-projects.

This is the build.gradle file:

apply plugin: 'java'

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

ant.importBuild 'build.xml'
ant.importBuild 'buildGWT.xml'

configurations {
	antClasspath
	testRuntime
	springmock
	tomcat
}

def jdkHome = System.getenv("JAVA_HOME")
dependencies {
	antClasspath files('/opt/TOMCAT/lib/ecj-4.2.2.jar')
	springmock fileTree(dir: 'WebRoot/WEB-INF/lib', include: 'spring-mock.jar')
	tomcat fileTree(dir: '/opt/TOMCAT/lib', include: '*.jar')
	testRuntime fileTree(dir: 'WebRoot/WEB-INF/classes')
	testRuntime fileTree(dir: 'WebRoot/WEB-INF/lib', include: '*.jar', excludes: ['spring-mock.jar'])
	testRuntime files('build/lib/selenium-server-standalone-2.46.0.jar')
}

// add additional jars to the AntBuilder classpath for use within the imported build.
ClassLoader antClassLoader = org.apache.tools.ant.Project.class.classLoader
configurations.antClasspath.each { File f -> antClassLoader.addURL(f.toURI().toURL())}

test {
	outputs.upToDateWhen { false }
	useJUnit()
	sourceSets.test.output.classesDir = file('WebRoot/WEB-INF/classes')
	sourceSets.test.output.resourcesDir = file('WebRoot/WEB-INF/classes')
	sourceSets.test.java.srcDirs = ['src/test', 'test']
	sourceSets.test.resources.srcDirs = ['src/resources']
	sourceSets.test.runtimeClasspath = sourceSets.test.runtimeClasspath + configurations.tomcat + configurations.springmock
    minHeapSize = "256m"
    maxHeapSize = "2560m"
    jvmArgs "-XX:MaxPermSize=256m", "-XX:+UseConcMarkSweepGC"

    systemProperties['webdriver.log.file'] = 'webdriver_js.log'
    systemProperties['webdriver.firefox.logfile'] = 'webdriver_ff.log'
	if (project.hasProperty('teamcity')) {
		systemProperties['strutstestcase.context.directory'] = teamcity['teamcity.build.checkoutDir'] + '/WebRoot'
		println "teamcity.build.checkoutDir = " + teamcity['teamcity.build.checkoutDir']
	}
	
	println "sourceSets.test.output.classesDir = " + sourceSets.test.output.classesDir
	println "testClassesDir = " + testClassesDir
	println "testSrcDirs = " + testSrcDirs
}

Hi Vladimir,

Thanks for the additional information. I tried again to reproduce the issue. Without success unfortunately.

Where do your test cases come from? Are they part of the normal Gradle test compilation or do you get them from some other place (because you modify test.runtimeClasspath?).

Do you think you can come up with a minimal example that reproduces the issue? I tried to create such an example, but without success.