The pillas of good unit tests
- There is no silver bullet in software development. Tests are definitly not one of it.
- When we do tests we should take in order:
- how long system supposed to live
- what is the price of changing tests
- how fragile your tests
- Test pyramid:
- a lot of unit tests
- small amount of integration tests
- very small amount of customer tests
Unit tests
- Can display error source
- Can provide a feedback quickly
- Can help in development
4.
Customer tests
- Long running time
- Do not display an error source
- Provide feedback - does system as a whole work or not
- If customer tests are made via UI then any change in UI will break them.
Unit tests best practices
- Should be very fast
- Do no mock everything, because mocking has a price - it decreases the thrustfullness of your tests and increase maintanance time
- Use Minimal Fixture
- Use Transient Fresh Fixture or just Fresh Fixture if first is not possible
- Don’t use condition
- If you use multile assert, make sure that you don’t lose information if second asset it not checked (when first one failes)