[GRADLE-3112] Filtered test task does not run tests that use the JUnit parameterized test runner Created: 25/Jun/14  Updated: 08/Feb/16  Resolved: 08/Feb/16

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 2.12-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Pepper Lebeck-Jobe
Resolution: Fixed Votes: 13


 Description   

Using Gradle 2.0-rc-1. JUnit 4.11

`gradle test` runs all of my tests out of the box. I add this to 'build.gradle' to differentiate unit tests:
```
test {
filter {
includeTestsMatching "test.*"
}
}
```
Then, any test annotated with `@RunWith(Parameterized.class)` is not included in the test run. Non-annotated tests run fine.

No error is displayed so it looks as if all tests have passed. But the test report and artifacts indicate clearly that none of those tests have been run.



 Comments   
Comment by zyro [ 12/Dec/14 ]

using gradle-2.2.1 and it looks like tests annotated with @RunWith(Parameterized.class) are not run at all (even without test.filter defined).

Comment by Reuben Sivan [ 23/Mar/15 ]

verified same issue still happens on Gradle 2.3

Comment by Andrey Agibalov [ 15/Apr/15 ]

Not sure if it's the same issue or not, but I never managed to run parameterized tests with gradlew test --tests *MyParameterizedTestClassNameHere. Gradle says it fails to find any tests matching this pattern (as of 2.1, 2.2 and 2.3).

Comment by James Stoddard [ 20/Jul/15 ]

I am unable to run parameterized tests as well. Gradle cannot find parameterized tests when run singly.

Comment by Benoit Désiré [ 14/Aug/15 ]

Hi

Here is a workaround that works for me:

test {
    doFirst {
        filter.includePatterns.each {
            include "${it.replaceAll('\\.', "\\${File.separator}")}.class"
        }
    }
}
Comment by James Stoddard [ 14/Aug/15 ]

Benoit,

Were you able to run java parameterized tests with your workaround? If so, what was your setup? I tried your workaround and it didn't work for me.

Thanks

Comment by Benoit Désiré [ 14/Aug/15 ]

Indeed sorry, i had the same pb with another custom runner.

Could you please try with

test {
    doFirst {
        filter.includePatterns.each {
            include "${it.replaceAll('\\.', "\\${File.separator}")}.class"
        }
        filter.setIncludePatterns('*')
    }
}

edit: The cmd is bit special, it requires the full name of the test class, it doesn't work with patterns (altough it could processed before setting the includes).
ex: gradle cleanTest test --tests com.mytests.TestParams --tests com.mytests.TestParams2

edit: this seems ok too:

gradle test --tests **.Test*
Comment by Marc Ewert [ 08/Oct/15 ]

This leads to the problem that parameterized tests couldn't be started directly in IntelliJ IDEA. I've reported a corresponding bug to the support team and they directed me to this bug.

Comment by TBD [ 10/Dec/15 ]

I encountered this problem as well. First I thought it is a problem of an old version but then I found this side after a quick search.

There is a very simple solution (at least with IntelliJ IDEA) which works even with Gradle 1.0: You have to add the Testclasses, which Gradle cannot detect as tests, in Run/Debug Configurations to JUnit and remove them from Gradle if necessary. Now, these "special" test classes should be able to run as tests on its own. Moreover if you build the whole project with Gradle, these parameter tests run as well and will also be included in the through Gradle generated HTML documentation.

I hope this spares some readers with the same problem a bit time finding a solution.

Generated at Wed Jun 30 12:40:18 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.