At <...>, we practice Test Driven Development. We expect you to write a test before you start working on a piece of functionality. We want at least one test for every small piece of functionality that you write.
- Do not write tests for functions or methods, write tests for functionality
- In a unit test you should be testing one unit of functionality, not a class or function. If you need 3 classes or functions to write a meaningful test for the functionality, then that's your unit.
- Use the lowest class of test you can, and the highest you have to: Unit → Integration → E2E. High test classes (for example E2E) help you test functionality instead of writing coverage tests. (high mock count, duplicated implementation, has to be adapted every time you change the functionality)
- My test needs a lot of mocks → you need a higher test class
- My test is duplicating the implementation → you need a higher test class
- It takes me minutes to run the tests for every small change → you need a lower test class
- My tests are very flaky → you need a lower test class
- Easy to read, are semantic, descriptive, concise
- Don't use a lot of mocking
- Treat the functionality as an idempotent function; data in → data out
- Test edgecases and security requirements
- Growing Object-Oriented Software Guided by Tests
- Test Driven Development by Example
- CodeCademy courses on TDD