Skip to content
Ameen Abozaid
Planned lessonJNR-047-L01

Arrange-Act-Assert and naming

  • Lesson 1 of 5
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

structure each test so it reads in seconds.

Planned topics

  • Arrange: set up data and collaborators. Act: call the thing under test once. Assert: check the outcome.
  • Separate the three parts with blank lines or comments.
  • Name tests by behavior: rejectsOrderWhenStockIsZero, not test1 or placeOrderTest.
  • One reason to fail per test; a name with "and" often means two tests.
  • Assert on outcomes, not on how the code got there.
Draft outline details

Demonstration

java
@Test
void rejectsOrderWhenStockIsZero() {
    var product = aProduct().withStock(0).build();       // arrange
    var result = service.place(orderOf(product));         // act
    assertThat(result.status()).isEqualTo(REJECTED);      // assert
}

Check your understanding

What does the "Act" step do?

Show answer

Calls the code under test, once.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.