Given, When, Then
A well-structured automated test is divided into three parts:
1 Given
Also called Arrange.
The first part of the test sets up the environment and creates any objects necessary for the system under test to work and to execute the specific test-case.
2 When
Also called Act.
The second part of the test executes the system under test using the environment set up in the first part and records any information that will be necessary for the last step.
3 Then
Also called Assert.
In the last step the test makes assertions on the behavior and results of what happened when the system under test was executed.
4 Related
4.1 Exceptions
It isn’t always “correct” to structure automated tests like this: