I’ve encountered an issue when using JUnit5 Nested tests. I have a single integration test class with a huge number of tests. I wanted to break up some of the tests into different classes, but only run the integration set up once for all the tests. So to do this, I used a pattern I’ve used before. I created the separate test classes, and then a parent class that includes all the integration set up. I’ve then created subclasses inside the parent class that each extend one of my classes that has a group of tests.
This works really well. I can run one class of tests, and I can get Gradle to run all the tests as part of the test suite. However, where it fails is if I want to run all the subclasses in the parent class. Gradle won’t run any tests, because the exact class match doesn’t work. I’ve created a small reproducible example that demonstrates what I mean: GitHub - Skater901/nested-gradle-test: Example showing how the enclosing class with nested JUnit 5 classes can't be run
My question is: is this behaviour expected? Using my sample code, if I want to run the tests for ExampleTest
, should I expect Gradle to only run the direct tests within that class? Or also the nested tests in the subclass? I would expect the latter, so I think this is a bug, but I want to clarify what the intentions are behind the test task and the test filtering.