Skip to content

refactor(tests): Use JUnit Jupiter mechanisms to handle general test setup and reporting#1543

Merged
rubenporras merged 1 commit into
eclipse-lsp4e:mainfrom
FlorianKroiss:use-junit-listeners
Jun 8, 2026
Merged

refactor(tests): Use JUnit Jupiter mechanisms to handle general test setup and reporting#1543
rubenporras merged 1 commit into
eclipse-lsp4e:mainfrom
FlorianKroiss:use-junit-listeners

Conversation

@FlorianKroiss

@FlorianKroiss FlorianKroiss commented Jun 4, 2026

Copy link
Copy Markdown
Contributor
  • The junit.jupiter.extensions.autodetection.enabled=true configuration automatically loads all listeners/extensions defined in META-INF/services. For example, we previously used the TestInfoExtension to log when a test starts. However, for this to work, you either had to manually add the extension to your test class or extend AbstractTest. Otherwise there would have been no output.
  • CloseIntroExtension is now a regular Extension which just makes sure the Intro is closed. This has the same advantage, that you don't have to use it explicitly or inherit from AbstractTest
  • LoggingTestExecutionListener is now used to report when a test case or test container starts/finish. This implements TestExecutionListener which has the advantage that it is called for each test, even for skipped ones and that you also get access to the result of the test case execution, which is something you cannot do with something like beforeEach/afterEach.
  • LoggingLauncherSessionListener is now used to redirect stderr and configure the java.util.logging. This implements LauncherSessionListener which is only called once per test session, instead of previously being done before each test case.

@FlorianKroiss FlorianKroiss changed the title refactor(tests): Use JUnit Jupiter mechanisms to handle general test … refactor(tests): Use JUnit Jupiter mechanisms to handle general test setup and reporting Jun 4, 2026
@FlorianKroiss

Copy link
Copy Markdown
Contributor Author

I have quite a few more changes lined up to make our tests less flaky but I did not want to make one mega PR 😄

@FlorianKroiss FlorianKroiss marked this pull request as ready for review June 4, 2026 13:20
@FlorianKroiss

FlorianKroiss commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

This should be good to go. The existing failures also exist on main.
The logging also seems to work:

  12:51:47 INFO [LoggingTestExecutionListener] Starting testFilterNonmatchingCompletions() 
  12:51:47 INFO [LoggingTestExecutionListener] Finished testFilterNonmatchingCompletions(): SUCCESSFUL 
  12:51:47 INFO [LoggingTestExecutionListener] Starting testPrefixCaseSensitivityWithoutTextEditAtOffset() 
  12:51:47 INFO [LoggingTestExecutionListener] Finished testPrefixCaseSensitivityWithoutTextEditAtOffset(): SUCCESSFUL 
  12:51:47 INFO [LoggingTestExecutionListener] Starting testCompleteOnFileEnd() 
  12:51:47 INFO [LoggingTestExecutionListener] Finished testCompleteOnFileEnd(): SUCCESSFUL 

@FlorianKroiss FlorianKroiss requested a review from rubenporras June 4, 2026 13:34
@rubenporras

Copy link
Copy Markdown
Contributor

@FlorianKroiss , I am not very familiar with JUnit best practices and extensions. Why do you think this is better that what LSP4E was doing so far? Could you explain it for a dummy user of JUnit?

@FlorianKroiss

FlorianKroiss commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@rubenporras It's basically about using the right callback for each purpose.

  • The junit.jupiter.extensions.autodetection.enabled=true configuration automatically loads all listeners/extensions defined in META-INF/services. For example, we previously used the TestInfoExtension to log when a test starts. However, for this to work, you either had to manually add the extension to your test class or extend AbstractTest. Otherwise there would have been no output.
  • CloseIntroExtension is now a regular Extension which just makes sure the Intro is closed. This has the same advantage, that you don't have to use it explicitly or inherit from AbstractTest
  • LoggingTestExecutionListener is now used to report when a test case or test container starts/finish. This implements TestExecutionListener which has the advantage that it is called for each test, even for skipped ones and that you also get access to the result of the test case execution, which is something you cannot do with something like beforeEach/afterEach.
  • LoggingLauncherSessionListener is now used to redirect stderr and configure the java.util.logging. This implements LauncherSessionListener which is only called once per test session, instead of previously being done before each test case.

Comment thread org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/AbstractTest.java Outdated
@rubenporras

Copy link
Copy Markdown
Contributor

@rubenporras It's basically about using the right callback for each purpose.

  • The junit.jupiter.extensions.autodetection.enabled=true configuration automatically loads all listeners/extensions defined in META-INF/services. For example, we previously used the TestInfoExtension to log when a test starts. However, for this to work, you either had to manually add the extension to your test class or extend AbstractTest. Otherwise there would have been no output.
  • CloseIntroExtension is now a regular Extension which just makes sure the Intro is closed. This has the same advantage, that you don't have to use it explicitly or inherit from AbstractTest
  • LoggingTestExecutionListener is now used to report when a test case or test container starts/finish. This implements TestExecutionListener which has the advantage that it is called for each test, even for skipped ones and that you also get access to the result of the test case execution, which is something you cannot do with something like beforeEach/afterEach.
  • LoggingLauncherSessionListener is now used to redirect stderr and configure the java.util.logging. This implements LauncherSessionListener which is only called once per test session, instead of previously being done before each test case.

Thanks, could you add this explanation to the PR and commit message?

@FlorianKroiss FlorianKroiss marked this pull request as draft June 5, 2026 08:08
…setup and reporting

- The `junit.jupiter.extensions.autodetection.enabled=true` configuration automatically loads all listeners/extensions defined in META-INF/services. For example, we previously used the `TestInfoExtension` to log when a test starts. However, for this to work, you either had to manually add the extension to your test class or extend AbstractTest. Otherwise there would have been no output.
- `CloseIntroExtension` is now a regular Extension which just makes sure the Intro is closed. This has the same advantage, that you don't have to use it explicitly or inherit from AbstractTest
- `LoggingTestExecutionListener` is now used to report when a test case or test container starts/finish. This implements `TestExecutionListener` which has the advantage that it is called for each test, even for skipped ones and that you also get access to the result of the test case execution, which is something you cannot do with something like beforeEach/afterEach.
- `LoggingLauncherSessionListener` is now used to redirect stderr and configure the java.util.logging. This implements `LauncherSessionListener` which is only called once per test session, instead of previously being done before each test case.
@FlorianKroiss FlorianKroiss force-pushed the use-junit-listeners branch from 6b7d87d to ace14b9 Compare June 5, 2026 08:19
@FlorianKroiss FlorianKroiss marked this pull request as ready for review June 5, 2026 08:19
@FlorianKroiss

FlorianKroiss commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, I forgot to commit some removed code.

@rubenporras rubenporras merged commit 99407b8 into eclipse-lsp4e:main Jun 8, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants