2

We are moving from our own proprietary java build tool to gradle.

Our own tool uses ANT and a custom org.apache.tools.ant.types.selectors.BaseExtendSelector to pull all things annotated with JUnit's @Test, resulting in some 4400 tests.

Running gradle test, I found some 5000 tests were run.

Further investigation revealed that we we have various usages of JUnit's @Suite:

@RunWith(Suite.class)
@Suite.SuiteClasses({
   FooTest.class,
   BarTest.class, ...
})
public class FooBarSuite {
}

where the listed tests FooTest, ... are all "ordinary" unit tests annotated with @Test. So the problem is that gradle "finds" all @Tests, but also all @Suites, and thus runs these twice.

Thus: is there a mechanism in gradle to simply ignore all the @Suite classes from execution (without specifying them manually by name)?

Note: I do know about JUnit categories, but that approach would require to rework our code base here. I am looking for a solution that works without editing all the suits.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • 1
    I assume you don't want to touch all your classes. If you still want to, then maybe [this](https://stackoverflow.com/a/18678108/5515060) is something for you. – Lino Mar 03 '21 at 13:20
  • you can ignore the totally test case., like [this](https://javabydeveloper.com/gradle-how-to-skip-exclude-unit-tests/) – Wang Du Mar 03 '21 at 13:40
  • 3
    @Lino Turns out: sometimes the best technical solution is ... to talk to people. All these suites were created years back, when we didn't have good means to run multiple tests. With our new gradle setup, everybody can run all unit tests within a few minutes ... so all owners of these suites agreed to have them deleted. – GhostCat Mar 04 '21 at 07:33
  • 1
    On the other hand, the fully technical answer seems to be: this isn't possible. One has to manually identify the corresponding suite classes and list them explicitly. Otherwise, real invention would be required by enhancing the default Test task to allow exclusion on actual filtering of "properties" of the specific java class objects. – GhostCat Mar 04 '21 at 07:36

0 Answers0