Uploaded image for project: 'Gradle'
  1. Gradle
  2. GRADLE-3112

Filtered test task does not run tests that use the JUnit parameterized test runner

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.12-rc-1
    • Gradle Forums topic Reference:

      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.

        Activity

        Hide
        zyro zyro added a comment -

        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).

        Show
        zyro zyro added a comment - 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).
        Hide
        rsivan Reuben Sivan added a comment -

        verified same issue still happens on Gradle 2.3

        Show
        rsivan Reuben Sivan added a comment - verified same issue still happens on Gradle 2.3
        Hide
        loki2302 Andrey Agibalov added a comment -

        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).

        Show
        loki2302 Andrey Agibalov added a comment - 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).
        Hide
        lonepilgrim James Stoddard added a comment -

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

        Show
        lonepilgrim James Stoddard added a comment - I am unable to run parameterized tests as well. Gradle cannot find parameterized tests when run singly.
        Hide
        benoitdesire Benoit Désiré added a comment -

        Hi

        Here is a workaround that works for me:

        test {
            doFirst {
                filter.includePatterns.each {
                    include "${it.replaceAll('\\.', "\\${File.separator}")}.class"
                }
            }
        }
        
        Show
        benoitdesire Benoit Désiré added a comment - Hi Here is a workaround that works for me: test { doFirst { filter.includePatterns.each { include "${it.replaceAll('\\.', " \\${File.separator} ")}.class" } } }
        Hide
        lonepilgrim James Stoddard added a comment -

        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

        Show
        lonepilgrim James Stoddard added a comment - 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
        Hide
        benoitdesire Benoit Désiré added a comment - - edited

        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*
        Show
        benoitdesire Benoit Désiré added a comment - - edited 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*
        Hide
        ewert Marc Ewert added a comment -

        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.

        Show
        ewert Marc Ewert added a comment - 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.
        Hide
        d_FRANK_b Frank W added a comment -

        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.

        Show
        d_FRANK_b Frank W added a comment - 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.

          People

          • Assignee:
            pepper Pepper Lebeck-Jobe
            Reporter:
            forums Gradle Forums
          • Votes:
            13 Vote for this issue
            Watchers:
            19 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development