Reference
Testing (`pkg14testing`)
Maven module demonstrating framework-agnostic Java testing.
Run
1mvn test -f pkg14testing/pom.xml2mvn -q exec:java -f pkg14testing/pom.xml # overviewWhat's covered
| Test class | Topic |
|---|---|
JUnit5BasicsTest |
assertions, lifecycle, @DisplayName, @Disabled |
MockitoDemoTest |
mocks, stubs, verify |
AssertJDemoTest |
fluent assertions |
ParameterizedTestDemo |
@ParameterizedTest, @CsvSource |
TddCalculatorTest |
red-green-refactor TDD |
PropertyBasedDemoTest |
jqwik properties |
Pyramid
- Unit (many): fast, isolated — this module
- Integration: DB/API with Testcontainers → SpringMastery
- E2E (few): full system paths
Best practices
- One logical assertion per test when possible; name tests as behavior.
- Use
@BeforeEachfor fresh fixtures; avoid shared mutable state. - Mock boundaries (DB, HTTP), not domain logic.
- Prefer AssertJ over raw
assertEqualsfor readability. - Property-based tests catch edge cases unit tests miss.