Skip to content

[SUREFIRE-1639] Add ability to configure JUnit 5 TestExecutionListener - #3438

Merged
olamy merged 1 commit into
apache:masterfrom
pan3793:SUREFIRE-1639-test-execution-listener
Aug 21, 2026
Merged

[SUREFIRE-1639] Add ability to configure JUnit 5 TestExecutionListener#3438
olamy merged 1 commit into
apache:masterfrom
pan3793:SUREFIRE-1639-test-execution-listener

Conversation

@pan3793

@pan3793 pan3793 commented Aug 19, 2026

Copy link
Copy Markdown
Member

Issue: #2122

Description

The listener provider property now accepts JUnit Platform
TestExecutionListener classes in addition to JUnit 4
org.junit.runner.notification.RunListener classes.

For each comma-separated entry, whitespace is trimmed and empty entries are
ignored. The provider then tries, in order:

  1. JUnit Platform TestExecutionListener (instantiated directly and registered
    with the Launcher)
  2. JUnit 4 RunListener (wrapped in JUnit4ListenersAdapter)
  3. otherwise ignored by this provider (TestNG listeners are forwarded to the
    TestNG engine via testng.listeners)

Changes

  • JUnitPlatformProvider resolves each listener entry as a JUnit Platform
    TestExecutionListener or a JUnit 4 RunListener, trimming whitespace and
    skipping empty entries.
  • Documents the new Registering a custom TestExecutionListener section in
    maven-surefire-plugin/src/site/markdown/examples/junit-platform.md.vm.
  • Adds unit test testExecutionListenerIsConfiguredViaListenerProperty and the
    junit5-testexecutionlistener integration test with
    JUnit5TestExecutionListenerIT.
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <properties>
      <property>
        <name>listener</name>
        <value>com.example.MyTestExecutionListener</value>
      </property>
    </properties>
  </configuration>
</plugin>

How it was tested

  • mvn -pl surefire-providers/surefire-junit-platform test -Dtest=JUnitPlatformProviderTest - 48 tests pass
  • mvn -pl surefire-providers/surefire-junit-platform checkstyle:check -
    no violations
  • Integration test JUnit5TestExecutionListenerIT verifies end-to-end that
    the configured listener runs in a forked test JVM

Checklist

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@pan3793
pan3793 force-pushed the SUREFIRE-1639-test-execution-listener branch from ab49f0f to c7a3973 Compare August 19, 2026 08:13
@pan3793 pan3793 changed the title [SUREFIRE-1639] Add ability to configure TestExecutionListener [SUREFIRE-1639] Add ability to configure JUnit 5 TestExecutionListener Aug 19, 2026
joseluisll added a commit to joseluisll/hadoop that referenced this pull request Aug 19, 2026
GenericTestUtils.waitFor dumps all threads with deadlock analysis to stderr
at the moment the wait expires. Its TimeoutException message drops from
~16KB to one line. Sample failure report: 18,223 -> 1,642 bytes.

TimedOutTestsListener implements TestExecutionListener. The `listener`
provider property the eight poms already carry binds to it once the JUnit
Platform provider accepts platform listeners (SUREFIRE-1639,
apache/maven-surefire#3438). Dormant until then. No pom is touched.

- -Dhadoop.test.timedout.dump=false disables dumps.
- -Dhadoop.test.timedout.dump.limit (default 5) caps them per JVM, with one
  elision notice. Both entry points share the budget.
- The exception records "Thread dump printed to stderr." only when a dump
  was printed.
- The two checkstyle violations the 2012 test file carried are fixed.

Not covered: Surefire's fork kill at forkedProcessTimeoutInSeconds
(Shutdown.KILL -> Runtime.halt()). HADOOP-19950 captures those reports.

Release note: waitFor's TimeoutException message no longer carries the
thread dump.

Tests: TestTimedOutTestsListener covers timeout detection, the off switch,
the dump limit, dumpForTimeout's return value, and waitFor's exact message
in all three states — dump printed, dumps off, budget spent, driving the
real waitFor. TestGenericTestUtils passes unchanged.

Contains content generated by Claude Code.
@pan3793

pan3793 commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

the test failure looks to be caused by a transient network issue

The listener provider property now accepts JUnit Platform
TestExecutionListener classes in addition to JUnit 4 RunListener classes.
Each comma-separated entry is trimmed and empty entries are ignored.
@pan3793
pan3793 force-pushed the SUREFIRE-1639-test-execution-listener branch from c7a3973 to d8e2164 Compare August 20, 2026 12:28
@pan3793

pan3793 commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

@olamy could you please take a look at this one too? thank you in advance

@olamy olamy added the enhancement New feature or request label Aug 20, 2026
@olamy olamy self-assigned this Aug 20, 2026
@olamy
olamy merged commit 0857364 into apache:master Aug 21, 2026
14 checks passed
@github-actions github-actions Bot added this to the 3.6.0-M2 milestone Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants