What does a good unit test look like with AAA and JUnit 5?
Short answer
A good unit test checks one behavior, runs fast, gives the same result every time, and never touches a DB or the network. Write it as AAA: prepare, call, check.
3 points to say:
- One behavior, fast, independent of other tests.
- Arrange, Act, Assert; the name states the behavior.
- Time and randomness: inject a
Clock.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.