Test Driven Development (TDD) is a development technique whose main principle is that we write our test cases before implementation of the functions(Unit Tests).It involves designing and developing tests for every small functionality.
Steps in TDD
- Write the function signature -Parameters that the function takes
- Write test cases for the function Should always fail at first because there is no implementation
- Write function logics to satisfy our test cases
Each test should only have a single assertion
Good tests should have the following characteristics
- Scope - This is the test coverage for our code.
- Speed - How fast our test cases run
- Fidelity- How close our test cases are to a real scenario
- Not a flaky test - Flaky tests are tests that sometimes succeeds and sometimes fails.
- Each tests should be independent
So Why TDD?
This approach helps take small significant steps when writing software.
Image by Ronny Overhate from Pixabay