On software testing
These are key principles for software testing:
- Code without tests automatically becomes legacy code
- Tests are not a target in themselves
- Code coverage is not a target in itself (Goodhart's law)
- Do not write tests when prototyping
- Every code path and use-case can be tested
- It is easier to test a non-existing code
- Code must, not should
- Try to keep tests isolated and streamlined
- Test helpers make tests harder to understand
- Write tests similar to the user interaction
-
Use Arrange-Act-Assert test structure:
- Set up the test environment
- Perform actions to achieve the result
- Check that the result is as expected
-
Use Red-Green-Refactor development cycle:
- Write the failing test
- Write the code for the test to pass
- Refactor the code