Unit test is a form of software development test that tests a small unit of logic. Most of the time, it will be a function that you write.
When to write unit tests
You should write unit tests for functions that has following characteristics:
- It has complex logic and there are a lot of edge cases to cover
- It is reusable across the whole application and if it is going break, it may have disastrous consequences for the business. It can be money conversion or temperature conversion.
Concepts
Spy
Mock
Testing Hooks
Testing Environment Setup