Skip to content

Commit 54d77f7

Browse files
committed
Fix reporting of Enclosed Parameterized tests in Vintage engine
Fixes #3083.
1 parent a0126dd commit 54d77f7

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.9.2.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ JUnit repository on GitHub.
4848

4949
==== Bug Fixes
5050

51-
* ❓
51+
* Fix reporting of `Parameterized` tests when used in combination with the `Enclosed`
52+
runner.
5253

5354
==== Deprecations and Breaking Changes
5455

junit-vintage-engine/src/main/java/org/junit/vintage/engine/execution/RunListenerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testSuiteFinished(Description description) {
9393
RunnerTestDescriptor runnerTestDescriptor = testRun.getRunnerTestDescriptor();
9494
// runnerTestDescriptor is reported in testRunFinished
9595
if (!runnerTestDescriptor.getDescription().equals(description)) {
96-
reportContainerFinished(lookupOrRegisterNextTestDescriptor(description));
96+
reportContainerFinished(lookupOrRegisterCurrentTestDescriptor(description));
9797
}
9898
}
9999

junit-vintage-engine/src/test/java/org/junit/vintage/engine/VintageTestEngineExecutionTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.junit.vintage.engine.samples.junit4.CompletelyDynamicTestCase;
6363
import org.junit.vintage.engine.samples.junit4.EmptyIgnoredTestCase;
6464
import org.junit.vintage.engine.samples.junit4.EnclosedJUnit4TestCase;
65+
import org.junit.vintage.engine.samples.junit4.EnclosedWithParameterizedChildrenJUnit4TestCase;
6566
import org.junit.vintage.engine.samples.junit4.IgnoredJUnit4TestCase;
6667
import org.junit.vintage.engine.samples.junit4.IgnoredParameterizedTestCase;
6768
import org.junit.vintage.engine.samples.junit4.JUnit4SuiteOfSuiteWithIgnoredJUnit4TestCase;
@@ -172,6 +173,39 @@ void executesEnclosedJUnit4TestCase() {
172173
event(engine(), finishedSuccessfully()));
173174
}
174175

176+
@Test
177+
void executesEnclosedWithParameterizedChildrenJUnit4TestCase() {
178+
Class<?> testClass = EnclosedWithParameterizedChildrenJUnit4TestCase.class;
179+
String commonNestedClassPrefix = EnclosedWithParameterizedChildrenJUnit4TestCase.class.getName()
180+
+ "$NestedTestCase";
181+
182+
execute(testClass).allEvents().debug().assertEventsMatchExactly( //
183+
event(engine(), started()), //
184+
event(container(testClass), started()), //
185+
event(container(commonNestedClassPrefix), started()), //
186+
event(container("[0]"), started()), //
187+
event(test("test[0]"), started()), //
188+
event(test("test[0]"), finishedSuccessfully()), //
189+
event(container("[0]"), finishedSuccessfully()), //
190+
event(container("[1]"), started()), //
191+
event(test("test[1]"), started()), //
192+
event(test("test[1]"), finishedSuccessfully()), //
193+
event(container("[1]"), finishedSuccessfully()), //
194+
event(container(commonNestedClassPrefix), finishedSuccessfully()), //
195+
event(container(commonNestedClassPrefix), started()), //
196+
event(container("[0]"), started()), //
197+
event(test("test[0]"), started()), //
198+
event(test("test[0]"), finishedSuccessfully()), //
199+
event(container("[0]"), finishedSuccessfully()), //
200+
event(container("[1]"), started()), //
201+
event(test("test[1]"), started()), //
202+
event(test("test[1]"), finishedSuccessfully()), //
203+
event(container("[1]"), finishedSuccessfully()), //
204+
event(container(commonNestedClassPrefix), finishedSuccessfully()), //
205+
event(container(testClass), finishedSuccessfully()), //
206+
event(engine(), finishedSuccessfully()));
207+
}
208+
175209
@Test
176210
void executesJUnit4SuiteWithJUnit3SuiteWithSingleTestCase() {
177211
Class<?> junit4SuiteClass = JUnit4SuiteWithJUnit3SuiteWithSingleTestCase.class;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2015-2022 the original author or authors.
3+
*
4+
* All rights reserved. This program and the accompanying materials are
5+
* made available under the terms of the Eclipse Public License v2.0 which
6+
* accompanies this distribution and is available at
7+
*
8+
* https://www.eclipse.org/legal/epl-v20.html
9+
*/
10+
11+
package org.junit.vintage.engine.samples.junit4;
12+
13+
import java.util.Arrays;
14+
import java.util.Collection;
15+
16+
import org.junit.Test;
17+
import org.junit.experimental.runners.Enclosed;
18+
import org.junit.runner.RunWith;
19+
import org.junit.runners.Parameterized;
20+
import org.junit.runners.Parameterized.Parameters;
21+
22+
// Source: https://github.com/junit-team/junit5/issues/3083
23+
@RunWith(Enclosed.class)
24+
public class EnclosedWithParameterizedChildrenJUnit4TestCase {
25+
26+
@RunWith(Parameterized.class)
27+
public static class NestedTestCase1 {
28+
29+
@Parameters
30+
public static Collection<Object[]> data() {
31+
return Arrays.asList(new Object[] { 1, 2 }, new Object[] { 3, 4 });
32+
}
33+
34+
@SuppressWarnings("unused")
35+
public NestedTestCase1(final int a, final int b) {
36+
}
37+
38+
@Test
39+
public void test() {
40+
}
41+
}
42+
43+
@RunWith(Parameterized.class)
44+
public static class NestedTestCase2 {
45+
46+
@Parameters
47+
public static Collection<Object[]> data() {
48+
return Arrays.asList(new Object[] { 1, 2 }, new Object[] { 3, 4 });
49+
}
50+
51+
@SuppressWarnings("unused")
52+
public NestedTestCase2(final int a, final int b) {
53+
}
54+
55+
@Test
56+
public void test() {
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)