JUnit 5 Extensions
1. Confirm That an Extension Is Warranted
- Use helpers, builders, or local fixtures first.
- Create an extension only when the behavior is cross-cutting and repeated.
- Read references/extension-patterns.md before adding a new extension.
- Read references/lifecycle-and-state.md before storing state or coordinating multiple callbacks.
2. Implement Deliberately
- Choose the smallest relevant callback or resolver interface.
- Keep state explicit and scoped safely.
- Keep extension behavior testable and unsurprising.
- Prefer explicit registration when discoverability matters.
- Keep meta-annotations small and intention-revealing.
3. Validate
- Add focused tests for the extension itself.
- Verify lifecycle ordering and failure behavior.
- Avoid hidden global behavior that changes unrelated tests.
- Read references/extension-testing.md when the extension has multiple callbacks or parameter rules.
4. Troubleshooting
- Problem: The extension hides too much setup. Fix: Move local test setup back into the test class and keep only the true cross-cutting concern in the extension.
- Problem: Parameter resolution is ambiguous. Fix: Narrow the supported parameter types or add clearer registration boundaries.
- Problem: The extension works only when tests run in a certain order. Fix: Remove hidden shared state and verify callback scope explicitly.