SteelReed

Search

Search posts, questions…

TestingQuestion 2 / 9

Junior

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.

Arrangedata, dependenciesActone actionAssertcheck the resultTest name describesbehavior

3 points to say:

  1. One behavior, fast, independent of other tests.
  2. Arrange, Act, Assert; the name states the behavior.
  3. 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.