Because it is by writing tests that you drive the development of your production code, TDD requires you to spend a lot of time thinking about what the next test is that you should write.
So how do we do this?
When you start to write a function, instead of writing a correct implementation, just return the result needed to make the test pass.
Where have we seen an example of this?
Which rule(s) of TDD does this help to enforce?
Useful for getting you started.
Tests can be like stairs – sometimes the whole purpose of a test is to allow you to write the next test. Once the first test leads you to where you are going, you can delete it.
Example: video at 20:00
Which rule(s) of TDD does this help to enforce?
Useful for getting you started.
Write test backwards – first write the assert, then iteratively fix one error at a time by adding only enough code needed to make the error go away.
Example: video at 27:55
Which rule(s) of TDD does this help to enforce?
Useful if you need help figuring out the setup for a test
Add a second specific test that will force you to modify the code you are currently testing to be more general.
Example: video at 34:17
two tests + code being tested = triangle
May lead to extracting an abstract class.
Which rule(s) of TDD does this help to enforce?
Your team has just completed a large project using TDD. All the production source code is on one hard drive, and all the testing code is on a second hard drive.
One hard drive has a catestrophic failure.
Which drive is the one you would hope would crash? The one with the production code? Or the one with the testing code?
Discuss
Uncle Bob’s answer at 59:10
What does a good test look like?
Golden Rule of Writing Tests:
Test behavior, not APIs.
Four rules of simple design:
Or in other words,
“First make it work, then make it right, then make it fast and small.” –Kent Beck