eclipse-jdt / eclipse-jdt/eclipse.jdt.ui
Feature Request: JUnit 5 Parameterized Test Filtering and Test Enable/Disable Functionality
- Dominant language
- Java
- Stars
- 59
- Forks
- 127
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 35
Description
## Summary
I would like to propose an enhancement to the JUnit view in Eclipse that significantly simplifies working with JUnit 5 parameterized tests (especially `@EnumSource`) and additionally provides a quick way to disable/enable tests directly from the JUnit view.
## Motivation
When working with parameterized tests in JUnit 5, there is currently a cumbersome workflow:
1. A single test case (e.g., a specific enum value) fails
2. To temporarily exclude it, you have to manually open the source file
3. The `@EnumSource` annotation must be manually adjusted with `mode = Mode.EXCLUDE` and `names = {...}`
4. The import for `Mode` must be added
This process is error-prone and time-consuming, especially when you want to iterate quickly.
## Proposed Functionality
### 1. Exclude Failing Test Cases (Context Menu)
Right-click on a failed parameterized test case in the JUnit view and select **"Exclude This Test Case"**. The `@EnumSource` annotation is automatically updated:
**Before:**
```java
@ParameterizedTest
@EnumSource(TestEnum.class)
void testWithEnum(TestEnum value) {
// test implementation
}
```
**After:**
```java
@ParameterizedTest
@EnumSource(value = TestEnum.class, mode = Mode.EXCLUDE, names = { "VALUE2" })
void testWithEnum(TestEnum value) {
// test implementation
}
```
The `Mode` import is automatically added to the file.
### 2. Test Disable/Enable (Context Menu)
- Right-click on any test in the JUnit view
- **"Disable This Test"** automatically adds `@Disabled` (JUnit 5) or `@Ignore` (JUnit 4)
- **"Enable This Test"** 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 (Submenu)
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 or **"Re-include All"**
The unused `Mode` import is automatically removed if no longer needed.
### 4. Quick Assist in Editor (Ctrl+1)
When editing a test file, place your cursor on an `@EnumSource` annotation and press **Ctrl+1** 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 show additional information in the JUnit view:
```
testWithEnum[VALUE1] - MyTest [@EnumSource(TestEnum)]
testWithEnum[VALUE2] - MyTest [@EnumSource(TestEnum)]
testWithEnum[VALUE3] - MyTest [@EnumSource(TestEnum)]
```
This helps quickly identify which source annotation is being used.
### 6. Validation of Enum Values (Quick Fix)
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.
## Typical Use Cases
**Scenario 1:** A parameterized test runs with 5 enum values, but VALUE3 causes a known issue.
1. Run tests
2. `testWithEnum[VALUE3]` fails
3. Right-click → "Exclude This Test Case"
4. Annotation is automatically updated
5. Re-run tests - VALUE3 is now skipped
6. Later: Right-click → "Re-include Excluded Values" → "VALUE3"
7. Test runs with all values again
**Scenario 2:** A regular test is failing and you want to skip it temporarily.
1. Run tests
2. `testSomething` fails
3. Right-click → "Disable This Test"
4. `@Disabled` is added
5. Re-run tests - test is skipped
6. Later: Right-click → "Enable This Test"
7. Test runs again
## Additional Features
- **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`).
## Prior Work
This functionality was already implemented in PR #2744. However, the PR was closed due to its size (23 changed files, ~4000 lines), which made reviewing difficult.
## 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 |
| `@RepeatedTest` | Disable/Enable via context menu |
| `@TestFactory` | Disable/Enable via context menu |
| `@TestTemplate` | Disable/Enable via context menu |
| `@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 |
## Benefits for Developers
- **Time savings**: No more manual editing of annotations
- **Fewer errors**: Automatic import management
- **Better workflow**: Work directly from the JUnit view
- **JUnit 4/5 compatible**: Automatic detection of JUnit version
- **Code quality**: Invalid enum references are detected and can be fixed
## Requirements
- Eclipse JDT UI
- JUnit 5 or JUnit 4 on the project classpath
- Java 8 or later
Contributor guide
Research direction
Start by reviewing the JUnit view and Quick Assist entry points in Eclipse JDT UI, then compare the requested JUnit 4/5 annotation and @EnumSource behavior with the scope of closed PR #2744. Done means the requested context-menu, editor-assist, filtering, enable/disable, display, and validation behaviors are implemented with the described import handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100