Can't run parent test class that only has JUnit nested tests inside

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.

I wouldn’t expect nested tests to run, because if you specify to run exactly the test class ExampleTest, then exactly that test alone is executed, and if you also want the nested ones, you use the pattern as you found out.

Yeah ok… it’s interesting, because Maven behaves differently through IntelliJ. If I do the same thing with Maven, I do get all the sub-tests to run as well. So if this is Gradle “working as intended”, then I think the issue is with IntelliJ, since the behaviour is inconsistent between Maven and Gradle. (Or maybe IntelliJ will just say “that’s how Maven and Gradle work”, we’ll see)

Well, I would consider it working as intended, but I’m just a user like you. :slight_smile: