Skip to content

Conversation

@carstenartur
Copy link
Contributor

What it does

JUnit 5 Parameterized Test Filtering for Eclipse JDT

Overview

This feature adds new capabilities to the Eclipse JUnit view that make it easier to work with JUnit 5 parameterized tests, especially those using @EnumSource. When a specific test case fails, you can now quickly exclude it without manually editing the source code.

Features

1. Exclude a Failing Test Case

When running a parameterized test with @EnumSource, each enum value appears as a separate test case in the JUnit view. If one of these test cases fails, you can now:

  1. Right-click on the failed test case (e.g., testWithEnum[VALUE2])
  2. Select "Exclude This Test Case"
  3. The source code is automatically updated:

Before:

@ParameterizedTest
@EnumSource(TestEnum.class)
void testWithEnum(TestEnum value) {
    // test implementation
}

After:

@ParameterizedTest
@EnumSource(value = TestEnum.class, mode = Mode. EXCLUDE, names = { "VALUE2" })
void testWithEnum(TestEnum value) {
    // test implementation
}

The Mode import is automatically added to your file.


2. Disable/Enable Test Methods

You can disable any test method directly from the JUnit view:

For regular JUnit tests:

  1. Right-click on a test case (e.g., testSomething)
  2. Select "Disable This Test"
  3. A @Disabled (JUnit 5) or @Ignore (JUnit 4) annotation is added

For parameterized tests:

  1. Right-click on the test method (e.g., testWithEnum(TestEnum))
  2. Select "Disable This Test"
  3. The entire parameterized test is disabled

If the test is already disabled, the menu shows "Enable This Test" instead, which removes the annotation.

This works for:

  • Regular JUnit 5 tests (@Test)
  • Regular JUnit 4 tests (@Test)
  • Parameterized tests (@ParameterizedTest)
  • Repeated tests (@RepeatedTest)
  • Test factories (@TestFactory)
  • Test templates (@TestTemplate)

3. Re-include Excluded Values

If you've previously excluded enum values and want to bring them back:

  1. Right-click on the parameterized test method
  2. Hover over "Re-include Excluded Values" submenu
  3. Choose:
    • A specific value (e. g., VALUE2) to re-include just that one
    • "Re-include All" to remove all exclusions

Before:

@EnumSource(value = TestEnum.class, mode = Mode. EXCLUDE, names = { "VALUE1", "VALUE2" })

After clicking "Re-include All":

@EnumSource(value = TestEnum.class)

The unused Mode import is automatically removed if no longer needed.


4. Quick Assist in Editor

When editing a test file, place your cursor on an @EnumSource annotation and press Ctrl+1 (or Cmd+1 on Mac) to see Quick Assist proposals:

  • "Add 'names' filter to @EnumSource" - Pre-populates with all enum values (INCLUDE mode)
  • "Add 'names' filter with EXCLUDE mode to @EnumSource" - Starts with empty exclusion list
  • "Toggle @EnumSource mode between INCLUDE and EXCLUDE" - Switches the filtering mode

For any JUnit test method, Quick Assist also offers:

  • "Disable test with @disabled" - Adds @Disabled annotation (JUnit 5)
  • "Disable test with @ignore" - Adds @Ignore annotation (JUnit 4)
  • "Enable test (remove @disabled)" - Removes the disable annotation

5. Enhanced Test Viewer Display

Parameterized tests now show additional information in the JUnit view:

testWithEnum[VALUE1] - MyTest [@EnumSource(TestEnum)]
testWithEnum[VALUE2] - MyTest [@EnumSource(TestEnum)]
testWithEnum[VALUE3] - MyTest [@EnumSource(TestEnum)]

This helps you quickly identify which source annotation is being used.


6. Validation of Enum Values

If you rename or delete an enum constant, but the @EnumSource annotation still references it, a Quick Fix is available:

  1. Place cursor on the @EnumSource annotation
  2. Press Ctrl+1
  3. Select "Remove invalid enum values from @EnumSource"

This removes any enum names that no longer exist in the enum class.


Workflow Example

Scenario: You have a parameterized test that runs with 5 enum values, but VALUE3 causes a known issue you want to temporarily skip.

  1. Run your tests
  2. testWithEnum[VALUE3] fails in the JUnit view
  3. Right-click on it → "Exclude This Test Case"
  4. The annotation is updated automatically
  5. Re-run tests - VALUE3 is now skipped
  6. Later, right-click on the test method → "Re-include Excluded Values""VALUE3"
  7. The test runs with all values again

Scenario: A regular test is failing and you want to skip it temporarily.

  1. Run your tests
  2. testSomething fails in the JUnit view
  3. Right-click on it → "Disable This Test"
  4. @Disabled is added to the method
  5. Re-run tests - the test is skipped (shown in grey)
  6. Later, right-click on the skipped test → "Enable This Test"
  7. The test runs again

Supported Annotations

Annotation Support Level
@Test (JUnit 5) Disable/Enable via context menu
@Test (JUnit 4) Disable/Enable via context menu
@ParameterizedTest Disable/Enable, Exclude values, Re-include values
@EnumSource Full support (exclude, re-include, validate)
@Disabled (JUnit 5) Add/remove via context menu and Quick Assist
@Ignore (JUnit 4) Add/remove via context menu and Quick Assist

Requirements

  • Eclipse JDT UI
  • JUnit 5 or JUnit 4 on the project classpath
  • Java 8 or later

Tips

  • Warning dialog: If excluding a value would leave only 0 or 1 values remaining, a confirmation dialog appears suggesting you might want to disable the entire test instead.

  • Clean imports: The feature automatically manages imports - adding Mode when needed and removing it when no longer used.

  • Works after running: You can enable a disabled parameterized test even after running the test class with @Disabled. The context menu correctly shows "Enable This Test" for ignored/skipped tests.

  • JUnit version detection: The feature automatically detects whether you're using JUnit 4 or JUnit 5 and uses the appropriate annotation (@Ignore vs @Disabled).

How to test

Author checklist

@trancexpress
Copy link
Contributor

This is about 4000 generated LoC. Should this be broken down into separate PRs at least?...

@carstenartur
Copy link
Contributor Author

This is about 4000 generated LoC. Should this be broken down into separate PRs at least?...

Sure, not a bad idea. We can remove the support for enumsource and get a much smaller change. Would be great to at least have support for disabling/enabling normal junit tests though (and even for that the implementation can be improved). I have no idea if anything here breaks because of the changes in downstream projects.

If you feel like suggesting a packaging, order or whatever you are welcome. The code is mostly generated using github Copilot so feel free to rearrange everything.

@carstenartur carstenartur marked this pull request as ready for review January 18, 2026 09:12
Copilot AI and others added 2 commits January 21, 2026 17:22
Removed merge conflict markers and cleaned up context menu entries for test viewer.
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