4

I want to run a single junit4 test suite and specified it using filter in build.gradle ,but gradle(version 2.10) find no tests. Is there a way to run a specified junit test suite in gradle?

My test suite class


    @RunWith(Suite.class)
    @SuiteClasses({ TestFoo.class, TestBar.class })
    public class MyTestSuite {

    }

build.gradle


    test {
        filter {
            includeTestsMatching "*MyTestSuite"
        }
    }

chao_chang
  • 778
  • 8
  • 14
  • The same problem: https://stackoverflow.com/questions/46719406/gradle-test-task-does-not-run-junit-test-with-category-and-runwith-annotations – isobretatel Oct 13 '17 at 12:48

2 Answers2

2

The example in the DSL documentation uses include instead:

test {
  // explicitly include or exclude tests
  include 'org/foo/**'
  exclude 'org/boo/**'
}
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • Yes,include works.(in my case by adding the line include '**/MyTestSuite.class').Filter just does not work with junit test suite? – chao_chang Jan 22 '16 at 02:27
0

filter is probably meant to be used in combination with include and exclude. Doc says: Allows filtering tests for execution.

So if you would like to run just a single method foo:

test {
  include '**MyTestSuite.class'
  filter {
            includeTestsMatching "*TestBar.foo"
  }
}
okocian
  • 488
  • 4
  • 11