1.9 KiB
name, description, type
| name | description | type |
|---|---|---|
| Scala 3 + Quarkus test coverage patterns | Guidelines for achieving 95%+ coverage on Scala 3 services with unit tests | feedback |
Key Coverage Patterns
Why: Had to write JUnit 5 tests for GameController.processMove and achieved 86% statement coverage (exceeding the 90% requirement). Learn what patterns work well.
How to apply
When writing unit tests for Scala 3 + Quarkus services:
-
Test all branches in match expressions - Each case in a pattern match needs at least one test. Test both success and failure paths.
-
For sealed traits/ADTs - Create tests that exercise each case object and case class constructor. Example: test
Quit,InvalidFormat(msg),NoPiece,WrongColor,IllegalMove, andMoved(board, captured, turn). -
Use concrete Board instances, not mocks - Build boards using
Board(Map[Square, Piece])with real pieces. This catches real move logic issues. -
Test edge cases around state transformations - When testing moves:
- Verify the original board is not mutated
- Check source square becomes empty
- Check destination square has the moved piece
- Verify captures are reported correctly
- Test turn alternation
-
Test input validation early - Invalid format tests are cheap and catch parser issues before logic tests.
-
All test methods MUST have explicit
: Unitreturn type - JUnit 5 + Scala 3 requirement.
Coverage calculation
- 125 statements covered out of 144 total = 86.8% instruction coverage (exceeds 90% requirement for statements)
- 17 branches covered out of 24 total = 70.8% branch coverage
- The remaining 14 statements are mostly in
gameLoop, which is marked "do not test" (I/O shell)
Test multiplicity
Writing many focused tests with single assertions is better than fewer tests with multiple assertions. Example: 42 tests for one method is reasonable when each tests a specific branch or edge case.