- If a bug is found one writes first a test which covers the bug and therefore fails, and then commit without push so others can reconstruct the error easily and afterwards one fixes the bug, regardless if one uses ‘Test Driven Development’ or not.
- Each class should have (at least) a unit-test class which does not deal with other classes of the system (a real unit-test) - use mocks where necessary.
- Make sure there are tests which cover a class if a new functionality has to be added to a class or a class has to be changed. If there are no tests or the tests do not cover the important parts of the class, the parts of the code you are going to change respectively, then create the necessary tests first.
- Do not refactor without tests, but refactor where necessary. Ergo, create tests if there are not any for the corresponding part of the code, hence you can refactor without introducing new bugs.
- Do write only against abstract types (interfaces or abstract classes) - if one class ignores this principle then it should be refactored. However, DTO's make an exception.
- If you exercise ‘Test Driven Development’ then:
- We write a unit test before the actual implementation whereby we incrementally add new unit tests and implementations (it is not wise to write first all tests and then the whole implementation - step by step; unit test, implementation, unit test implementation etc.).