A while back Oren wrote about the Arrange, Act, Assert syntax for unit tests. I've seen several other discussions on this and I am not sure if he is the originator but I'll attribute him either way.
The syntax I most commonly use ressembles an Arrange, Assert, Act and Assert (AAAA) pattern.
The syntax I most commonly use ressembles an Arrange, Assert, Act and Assert (AAAA) pattern.
- Arrange the system in it's initial configuration. Create any collaborators and mocks you may need. Initialize services.
- Assert that the initial state is correct. For me this is important since so many layer of dependencies exist in modern applications. This is analogous to a control group in the scientific method. In this step I would also test the inverse of later assertion such as the non-existence of objects that should only exist after the Act step.
- Act on the system by creating/deleting/updating new objects or invoking services.
- Assert again that the system is in it's expected state.