> A unit test exercises the smallest piece of testable software in the application to determine whether it behaves as expected.
> The size of the unit under test is not strictly defined. The smaller the unit under test the easier it is to express the behaviour using a unit test since the branch complexity of the unit is lower.[^mf1]
[^mf1]: [Testing Strategies in a Microservices Architecture (slides)](https://martinfowler.com/articles/microservice-testing/#testing-unit-introduction) by [[Martin Fowler]]
## Benefits of unit testing
- Can be used as a module design tool in addition to a verification tool, especially when combined with [[Test Driven Development (TDD)]]
- Quick to run as it only executes a very small part of code
- Parallelisation-friendly: they should have no side effects and don't require a deployed system so can take advantage
## Styles of unit testing [^mf1]
Since [[Unit test as a term is not commonly understood]], there are a few different styles of unit tests that can implemented:
[^mf1]: [Testing Strategies in a Microservices Architecture (slides)](https://martinfowler.com/articles/microservice-testing/#testing-unit-introduction) by [[@Martin Fowler]]
### Sociable unit testing
This focuses on testing the behaviour of modules by observing changes in their state. This treats the unit under test as a black box tested entirely through its interface.
### Solitary unit testing
This looks at the interactions and collaborations between an object and its dependencies, which are replaced by [[Test double]]s.