AAA (Arrange, Act and Assert)

The AAA pattern advocates for splitting each test into three parts: arrange, act and assert. This pattern provides a simple and uniform structure for all the tests in the set. This uniformity is one of the main advantages of this pattern: once you get used to it, you can easily read and understand any test. That, in turn, reduces maintenance costs for the entire test suite.

example.spec.ts
it('Verify the enter key works', () => {
    //Arrange
    grid().should('be.exist');
    grid().should('be.visible');
    cellToEdit(0,3).should('be.visible');
    
    //Act
    cellToEdit(0,3).click();
    
    inputCell(1,3).should('be.visible');
    inputCell(1,3).should('be.visible');
    
    inputCell(1,3).type('500 {enter}');
    
    inputCell(2,3).should('be.visible');
    inputCell(2,3).should('be.visible');
    
    inputCell(2,3).type('500 {enter}');
    
    //Assert
    totalRowValue().should('have.text', ' $1000 ');
})

Arrange

This section is generally used to prepare the environment and make sure that it is in the initial state. In this section you can verify that you are in the correct view by identifying, for example, whether the components to be tested exist, do not exist, are visible or invisible.

The assertions that can be made in this section (Arrange) are not the same as those in the "Assert" section, they are generally used to verify that everything is ready, while those in the other section are to verify that the behavior to be tested works.

Act

In this section all the actions necessary to achieve the test objective are performed. For example, if you need to edit a cell, all the actions for clicking in the cell, typing text and changing the focus should be here.

Unlike unit tests, this section can have several lines of code, as many as necessary to achieve the desired functionality.

The assertions that can be made in this section (Act) are not the same as those in the "Assert" section, they are generally used to verify that the steps or actions taken are on track.

Assert

In this step, you assert that the thing you acted upon in step two did what you expected.

Last updated