Skip to content

Commit 3d5a35c

Browse files
committed
Group test cases inside nested class
1 parent 83c4bc1 commit 3d5a35c

File tree

2 files changed

+131
-126
lines changed

2 files changed

+131
-126
lines changed

jupiter-tests/src/test/java/org/junit/jupiter/engine/discovery/DiscoveryTests.java

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void discoverDeeplyNestedTestMethodByNestedMethodSelector() throws Exception {
177177
@MethodSource("requestsForTestClassWithInvalidTestMethod")
178178
void reportsWarningForTestClassWithInvalidTestMethod(LauncherDiscoveryRequest request) throws Exception {
179179

180-
var method = InvalidTestMethodTestCase.class.getDeclaredMethod("test");
180+
var method = InvalidTestCases.InvalidTestMethodTestCase.class.getDeclaredMethod("test");
181181

182182
var results = discoverTests(request);
183183

@@ -194,14 +194,15 @@ void reportsWarningForTestClassWithInvalidTestMethod(LauncherDiscoveryRequest re
194194

195195
static List<Named<LauncherDiscoveryRequest>> requestsForTestClassWithInvalidTestMethod() {
196196
return List.of( //
197-
named("directly selected", request().selectors(selectClass(InvalidTestMethodTestCase.class)).build()), //
197+
named("directly selected",
198+
request().selectors(selectClass(InvalidTestCases.InvalidTestMethodTestCase.class)).build()), //
198199
named("indirectly selected", request() //
199-
.selectors(selectPackage(InvalidTestMethodTestCase.class.getPackageName())) //
200-
.filters(
201-
includeClassNamePatterns(Pattern.quote(InvalidTestMethodTestCase.class.getName()))).build()), //
200+
.selectors(selectPackage(InvalidTestCases.InvalidTestMethodTestCase.class.getPackageName())) //
201+
.filters(includeClassNamePatterns(
202+
Pattern.quote(InvalidTestCases.InvalidTestMethodTestCase.class.getName()))).build()), //
202203
named("subclasses", request() //
203-
.selectors(selectClass(InvalidTestMethodSubclass1TestCase.class),
204-
selectClass(InvalidTestMethodSubclass2TestCase.class)) //
204+
.selectors(selectClass(InvalidTestCases.InvalidTestMethodSubclass1TestCase.class),
205+
selectClass(InvalidTestCases.InvalidTestMethodSubclass2TestCase.class)) //
205206
.build()) //
206207
);
207208
}
@@ -224,16 +225,18 @@ void reportsWarningForInvalidStandaloneTestClass(LauncherDiscoveryRequest reques
224225

225226
static List<Arguments> requestsForTestClassWithInvalidStandaloneTestClass() {
226227
return List.of( //
227-
argumentSet("directly selected", request().selectors(selectClass(InvalidTestClassTestCase.class)).build(),
228-
InvalidTestClassTestCase.class), //
228+
argumentSet("directly selected",
229+
request().selectors(selectClass(InvalidTestCases.InvalidTestClassTestCase.class)).build(),
230+
InvalidTestCases.InvalidTestClassTestCase.class), //
229231
argumentSet("indirectly selected", request() //
230-
.selectors(selectPackage(InvalidTestClassTestCase.class.getPackageName())) //
231-
.filters(includeClassNamePatterns(Pattern.quote(InvalidTestClassTestCase.class.getName()))).build(), //
232-
InvalidTestClassTestCase.class), //
232+
.selectors(selectPackage(InvalidTestCases.InvalidTestClassTestCase.class.getPackageName())) //
233+
.filters(includeClassNamePatterns(
234+
Pattern.quote(InvalidTestCases.InvalidTestClassTestCase.class.getName()))).build(), //
235+
InvalidTestCases.InvalidTestClassTestCase.class), //
233236
argumentSet("subclass", request() //
234-
.selectors(selectClass(InvalidTestClassSubclassTestCase.class)) //
237+
.selectors(selectClass(InvalidTestCases.InvalidTestClassSubclassTestCase.class)) //
235238
.build(), //
236-
InvalidTestClassSubclassTestCase.class) //
239+
InvalidTestCases.InvalidTestClassSubclassTestCase.class) //
237240
);
238241
}
239242

@@ -247,18 +250,19 @@ void reportsWarningForInvalidNestedTestClass(LauncherDiscoveryRequest request) {
247250
assertThat(discoveryIssues).hasSize(2);
248251
assertThat(discoveryIssues.getFirst().message()) //
249252
.isEqualTo("@Nested class '%s' must be an inner class but is static. It will not be executed.",
250-
InvalidTestClassTestCase.Inner.class.getName());
253+
InvalidTestCases.InvalidTestClassTestCase.Inner.class.getName());
251254
assertThat(discoveryIssues.getLast().message()) //
252255
.isEqualTo("@Nested class '%s' must not be private. It will not be executed.",
253-
InvalidTestClassTestCase.Inner.class.getName());
256+
InvalidTestCases.InvalidTestClassTestCase.Inner.class.getName());
254257
}
255258

256259
static List<Named<LauncherDiscoveryRequest>> requestsForTestClassWithInvalidNestedTestClass() {
257260
return List.of( //
258-
named("directly selected", request().selectors(selectClass(InvalidTestClassTestCase.Inner.class)).build()), //
261+
named("directly selected",
262+
request().selectors(selectClass(InvalidTestCases.InvalidTestClassTestCase.Inner.class)).build()), //
259263
named("subclass", request() //
260-
.selectors(selectNestedClass(List.of(InvalidTestClassSubclassTestCase.class),
261-
InvalidTestClassTestCase.Inner.class)) //
264+
.selectors(selectNestedClass(List.of(InvalidTestCases.InvalidTestClassSubclassTestCase.class),
265+
InvalidTestCases.InvalidTestClassTestCase.Inner.class)) //
262266
.build()) //
263267
);
264268
}
@@ -331,41 +335,45 @@ class ConcreteInner1 extends AbstractSuperClass {
331335
}
332336
}
333337

334-
@SuppressWarnings("JUnitMalformedDeclaration")
335-
static class InvalidTestMethodTestCase {
336-
@Test
337-
private static int test() {
338-
return fail("should not be called");
339-
}
340-
}
341-
342-
static class InvalidTestMethodSubclass1TestCase extends InvalidTestMethodTestCase {
343-
}
338+
static class InvalidTestCases {
344339

345-
static class InvalidTestMethodSubclass2TestCase extends InvalidTestMethodTestCase {
346-
}
340+
@SuppressWarnings("JUnitMalformedDeclaration")
341+
static class InvalidTestMethodTestCase {
342+
@Test
343+
private static int test() {
344+
return fail("should not be called");
345+
}
346+
}
347347

348-
@SuppressWarnings({ "JUnitMalformedDeclaration", "InnerClassMayBeStatic" })
349-
private class InvalidTestClassTestCase {
348+
static class InvalidTestMethodSubclass1TestCase extends InvalidTestMethodTestCase {
349+
}
350350

351-
@SuppressWarnings("unused")
352-
@Test
353-
void test() {
354-
fail("should not be called");
351+
static class InvalidTestMethodSubclass2TestCase extends InvalidTestMethodTestCase {
355352
}
356353

357-
@Nested
358-
private static class Inner {
354+
@SuppressWarnings({ "JUnitMalformedDeclaration", "InnerClassMayBeStatic" })
355+
private class InvalidTestClassTestCase {
356+
359357
@SuppressWarnings("unused")
360358
@Test
361359
void test() {
362360
fail("should not be called");
363361
}
362+
363+
@Nested
364+
private static class Inner {
365+
@SuppressWarnings("unused")
366+
@Test
367+
void test() {
368+
fail("should not be called");
369+
}
370+
}
371+
364372
}
365373

366-
}
374+
private class InvalidTestClassSubclassTestCase extends InvalidTestClassTestCase {
375+
}
367376

368-
private class InvalidTestClassSubclassTestCase extends InvalidTestClassTestCase {
369377
}
370378

371379
}

0 commit comments

Comments
 (0)