TDD consists of a rapid repetition of the following steps:
- Identify the smallest functional unit of your feature that has not yet been implemented.
- Identify a test case and write a test for it. You may want to have test cases that cover the happy path, which is the default scenario that produces no errors or exceptions, as well as unhappy paths, including dealing with edge cases.
- Run the test and see it fail.
- Write the minimum amount of code to make it pass.
- Refactor the code.
For example, if we want to build a math utility library, then our first iteration of the TDD cycle may look like this: