Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void dynamicTestRegistered(TestDescriptor testDescriptor) {
@Override
public void reportingEntryPublished(TestDescriptor testDescriptor, ReportEntry entry) {
// tracing listener is not interested in this event
delegate.dynamicTestRegistered(testDescriptor);
delegate.reportingEntryPublished(testDescriptor, entry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ import org.example.TestSucceedUnskippable
import org.example.TestSucceedUnskippableSuite
import org.example.TestSucceedVerySlow
import org.example.TestSucceedWithCategories
import org.example.TestSucceedWithReportEntry
import org.example.TestSuiteSetUpAssumption
import org.example.TestTemplate
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.engine.JupiterTestEngine
import org.junit.platform.engine.DiscoverySelector
import org.junit.platform.engine.TestExecutionResult
import org.junit.platform.engine.reporting.ReportEntry
import org.junit.platform.launcher.TestExecutionListener
import org.junit.platform.launcher.core.LauncherConfig
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder
Expand Down Expand Up @@ -260,6 +262,15 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {
"test-attempt-to-fix-disabled-succeeded" | true | [TestSucceed] | [new TestFQN("org.example.TestSucceed", "test_succeed")] | [] | [new TestFQN("org.example.TestSucceed", "test_succeed")]
}

def "forwards report entries to the launcher listeners"() {
when:
def listener = runTests([TestSucceedWithReportEntry])

then:
listener.reportEntries*.keyValuePairs == [["key": "value"]]
listener.dynamicTests.isEmpty()
}

def "test capabilities tagging #testcaseName"() {
setup:
Assumptions.assumeTrue(!JUnitPlatformUtils.isJunitTestOrderingSupported(instrumentedLibraryVersion()))
Expand All @@ -269,7 +280,7 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {
assertCapabilities(JUnitPlatformUtils.JUNIT_CAPABILITIES_BASE, 4)
}

protected void runTests(List<Class<?>> tests, boolean expectSuccess = true) {
protected TestResultListener runTests(List<Class<?>> tests, boolean expectSuccess = true) {
DiscoverySelector[] selectors = new DiscoverySelector[tests.size()]
for (i in 0..<tests.size()) {
selectors[i] = selectClass(tests[i])
Expand Down Expand Up @@ -301,6 +312,7 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {
throw new AssertionError("Expected a failed execution, got no failed tests")
}
}
return listener
} finally {
TestEventsHandlerHolder.stop()
}
Expand All @@ -323,6 +335,16 @@ class JUnit5Test extends CiVisibilityInstrumentationTest {

private static final class TestResultListener implements TestExecutionListener {
private final Map<TestExecutionResult.Status, Collection<org.junit.platform.launcher.TestIdentifier>> testsByStatus = new ConcurrentHashMap<>()
private final Collection<ReportEntry> reportEntries = new CopyOnWriteArrayList<>()
private final Collection<org.junit.platform.launcher.TestIdentifier> dynamicTests = new CopyOnWriteArrayList<>()

void reportingEntryPublished(org.junit.platform.launcher.TestIdentifier testIdentifier, ReportEntry entry) {
reportEntries.add(entry)
}

void dynamicTestRegistered(org.junit.platform.launcher.TestIdentifier testIdentifier) {
dynamicTests.add(testIdentifier)
}

void executionFinished(org.junit.platform.launcher.TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
testsByStatus.computeIfAbsent(testExecutionResult.status, k -> new CopyOnWriteArrayList<>()).add(testIdentifier)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestReporter;

public class TestSucceedWithReportEntry {

@Test
public void test_succeed_with_report_entry(TestReporter reporter) {
reporter.publishEntry("key", "value");
}
}
Loading