Getting started with unit testing
The ultimate aim of unit testing is to test a specific piece of code/component in isolation to make sure that components work according to specification. This reduces the chances of failures/bugs in the component when integrated with other parts of the software. Before we start writing tests, there are some guidelines that can help us write good and maintainable tests:
- One unit should test one behavior. For obvious reasons, testing one behavior per unit test makes sense. A failing unit test should clearly highlight the problem area. If multiple behaviors are tested together, a failed test requires more probing to assert what behavior was violated.
- Dependencies in a unit test should be mocked away. Unit testing, ...