Chapter 9 - Unit Tests
-
3 laws of Test Driven Development (TDD)
- You may not write production code without writting a failing unit test
- You may not write more of a unit test than is sufficient to fail
- You may not write more production code than is sufficient to pass the current failing test
-
These laws lock you into a cycle of writting tests with production code
-
Keep Tests Clean
- Test should be at the same standard as production code
- A messy test is the same as having no tests
-
What Makes a Clean Tests:
- High Readability
- High Clarity
- Simplicity
- High Density of Expressions (say a lot with as few expressions)
-
Have a Single Concept per Test
- Don't have long test functions. We want to find quickly in our code where the problem is
- Having a single assert per test is a good guideline to follow
-
F.I.R.S.T
- Clean Tests follow 5 other rules
- Fast (Runs quickly)
- Independant (One test doesn't rely on another)
- Repeatable (Can be run in any enviroment)
- Self validating (Boolean output, true or false)
- Timely (written quickly, runs timely)
- Clean Tests follow 5 other rules