Java Unit Test Rules
1. Framework
- Use JUnit 5 as the default testing framework.
2. Structure
- Follow Arrange–Act–Assert pattern.
- Each test should clearly define input, execution, and assertions.
3. Naming
- Test method names should describe the behavior, e.g.,
shouldReturnFalseForInvalidPassword
.
4. Edge Cases
- Always test for:
- Null values
- Empty strings
- Invalid formats
5. Mocking
- Use Mockito when testing service classes with dependencies.
6. Readability
- Prefer one assertion per test when possible.
- Use
@BeforeEach
to initialize shared test objects.