Every clean unit test has three sections in order. Click a section to highlight it — or "Show all" to see the whole test.
// RoomTest.java
@Test
public voidcheckIn_RoomInitialStatus_RoomIsOccupiedAndDirty() {
// Arrange
Room room = newRoom(2, 100.0);
// Act
room.checkIn();
// Assert
assertTrue(room.isOccupied());
assertTrue(room.isDirty());
}
All three sections
Read top to bottom — like a tiny script
A clean unit test reads in three beats. Set up → do one thing → check the result. Anything else (extra method calls, multiple acts, complicated logic) belongs in a different test or in a private helper.
Test naming — 3 underscored parts
1. Method under test
checkIn
2. State under test
RoomInitialStatus
3. Expected behavior
RoomIsOccupiedAndDirty
Pattern:methodUnderTest_StateUnderTest_ExpectedBehavior. Each name reads as a tiny spec: which method, in what state, expecting what. Other styles exist (e.g. shouldDoX_whenY, doX_givenY_thenZ). Pick one for your project — and stick with it. Mixing styles inside one test class is the actual problem.