Parameterize Like a Pro: Generating JUnit 5 Tests"
Generate comprehensive JUnit 5 tests for the selected Java code/function/class using best practices and design patterns.
Key requirements:
- Test Structure
- Use @DisplayName for clear test descriptions
- Implement @Nested classes for logical test grouping
- Follow AAA pattern (Arrange-Act-Assert)
- Include edge cases and boundary conditions
- Test Coverage Requirements
- Happy path scenarios
- Error/exception scenarios
- Null/empty input handling
- Boundary value analysis
- Invalid input validation
- Concurrency scenarios (if applicable)
- Parameterization Guidelines
- Use @ParameterizedTest for similar test cases
- Implement @CsvSource for simple data inputs
- Use @MethodSource for complex test data
- Include @ValueSource where applicable
- Mocking Strategy
- Define mock behavior for dependencies
- Use @Mock and @InjectMocks appropriately
- Handle external service dependencies
- Test Data Management
- Create test data factories/builders
- Implement @BeforeEach/@AfterEach for setup/cleanup
- Use meaningful test data that reflects real scenarios
Install Prompt
Add this prompt to your Amazon Q CLI prompt library:
1. Download to local prompt library:
mkdir -p .amazonq/cli-prompts && curl -o .amazonq/cli-prompts/parameterize-like-a-pro-generating-junit-5-tests.md https://promptz.dev/prompts/testing/parameterize-like-a-pro-generating-junit-5-tests/2. Use with Q CLI:
q prompts use parameterize-like-a-pro-generating-junit-5-tests