|
12 | 12 |
|
13 | 13 | import static java.util.Collections.emptyMap; |
14 | 14 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 15 | +import static org.junit.jupiter.engine.Constants.DEFAULT_TEST_INSTANCE_LIFECYCLE_PROPERTY_NAME; |
| 16 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; |
| 17 | +import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request; |
15 | 18 |
|
16 | 19 | import java.util.HashMap; |
17 | 20 | import java.util.Map; |
18 | 21 |
|
19 | 22 | import org.junit.jupiter.api.AfterEach; |
20 | 23 | import org.junit.jupiter.api.BeforeEach; |
21 | 24 | import org.junit.jupiter.api.Test; |
| 25 | +import org.junit.jupiter.api.TestInstance.Lifecycle; |
22 | 26 | import org.junit.jupiter.api.TestReporter; |
| 27 | +import org.junit.jupiter.params.ParameterizedTest; |
| 28 | +import org.junit.jupiter.params.provider.CsvSource; |
23 | 29 | import org.junit.platform.commons.PreconditionViolationException; |
24 | 30 |
|
25 | 31 | /** |
26 | 32 | * @since 5.0 |
27 | 33 | */ |
28 | 34 | class ReportingTests extends AbstractJupiterTestEngineTests { |
29 | 35 |
|
30 | | - @Test |
31 | | - void reportEntriesArePublished() { |
32 | | - executeTestsForClass(MyReportingTestCase.class).testEvents().assertStatistics(stats -> stats // |
33 | | - .started(2) // |
34 | | - .succeeded(2) // |
35 | | - .failed(0) // |
36 | | - .reportingEntryPublished(7)); |
| 36 | + @ParameterizedTest |
| 37 | + @CsvSource(textBlock = """ |
| 38 | + PER_CLASS, 7 |
| 39 | + PER_METHOD, 9 |
| 40 | + """) |
| 41 | + void reportEntriesArePublished(Lifecycle lifecycle, int expectedReportEntryCount) { |
| 42 | + var request = request() // |
| 43 | + .selectors(selectClass(MyReportingTestCase.class)) // |
| 44 | + .configurationParameter(DEFAULT_TEST_INSTANCE_LIFECYCLE_PROPERTY_NAME, lifecycle.name()); |
| 45 | + executeTests(request) // |
| 46 | + .testEvents() // |
| 47 | + .assertStatistics(stats -> stats // |
| 48 | + .started(2) // |
| 49 | + .succeeded(2) // |
| 50 | + .failed(0) // |
| 51 | + .reportingEntryPublished(expectedReportEntryCount)); |
37 | 52 | } |
38 | 53 |
|
39 | 54 | static class MyReportingTestCase { |
40 | 55 |
|
| 56 | + public MyReportingTestCase(TestReporter reporter) { |
| 57 | + // Reported on class-level for PER_CLASS lifecycle and on method-level for PER_METHOD lifecycle |
| 58 | + reporter.publishEntry("Constructor"); |
| 59 | + } |
| 60 | + |
41 | 61 | @BeforeEach |
42 | 62 | void beforeEach(TestReporter reporter) { |
43 | 63 | reporter.publishEntry("@BeforeEach"); |
|
0 commit comments