vscode-java-test icon indicating copy to clipboard operation
vscode-java-test copied to clipboard

Test Runner for Java ignores @BeforeAll annotations on test classes

Open demonfiddler opened this issue 11 months ago • 1 comments

Symptom: JUnit 5 test methods in a test class with an @BeforeAll method are correctly initialised and pass when run with gradlew test but do not get correctly initialised and fail when the test method is run individually in the VSCode IDE.

System: Windows 10, VSCode 1.96.3, Gradle 8.12, Spring Boot 3.4.1, Java 21.04, JUnit 5.11.4

Related issue: #1748

demonfiddler avatar Mar 17 '25 11:03 demonfiddler

Hi @demonfiddler, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

Suggestions:

  • Ensure your @BeforeAll method is static, or annotate the test class with @TestInstance(Lifecycle.PER_CLASS) to allow non-static @BeforeAll methods. See JUnit 5 docs:

    • https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations
  • Update the Java Test Runner extension to the latest version, which includes fixes for @BeforeAll initialization when running individual tests.

Other references with high confidence:

  • Issue #931: unhandled exceptions in @BeforeAll (must be static or use @TestInstance(PER_CLASS)); real error hidden in Output window • https://github.com/microsoft/vscode-java-test/issues/931

duplicateUrls:

  • https://github.com/microsoft/vscode-java-test/issues/1748

The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

github-actions[bot] avatar Nov 13 '25 00:11 github-actions[bot]