The Single-Behavior guideline
Every unit test should test one and only one behavior. Throughout this book, this concept has been enforced naturally by:
- The naming of the unit test method’s signature, which reflects one condition with one expectation
- A single AAA structure that enforced a single
Act
Before digging further, I would like to define the word behavior.
What is behavior?
The definition of behavior varies in the industry, so it is important to set an accurate one for the context of this book. Each SUT is supposed to do something. A SUT does this thing by:
- Communicating with dependencies: Communication can be by calling a method on a dependency or setting a field or a property – this is referred to as external behavior.
- Returning a value to the outside world (the caller): This could be via an
Exception
or the return value (if a method is not avoid
or aTask
method) – this is also referred to as external behavior.
...