Structuring Tests Using the AAA Approach

Learn to structure tests using the AAA approach.

We'll cover the following

AAA approach

AAA stands for Approach-Act-Assert.

  • In the Approach phase, we initialize the piece of the unit we want to test. This means we create the required objects and test data.

  • In the Act phase, we execute the code to be verified. This is usually a method or a function.

  • In the Assert phase, we verify whether the behavior of the method matches our expectations.

Example

We’ll use the code below, the Calculator.java class, to test and demonstrate the AAA approach.

Get hands-on with 1400+ tech skills courses.