Testing First Drives Design
Success with test-driven development starts with trusting the process. The classic process goes like this:
-
Create a test. The test should be short and test for one thing in your code. The test should run automatically.
-
Make sure the test fails. Verifying the test failure before you write code helps ensure that the test really does what you expect.
-
Write the simplest code that could possibly make the test pass. Donât worry about good code yet. Donât look ahead. Sometimes, write just enough code to clear the current error.
-
After the test passes, refactor to improve the code. Clean up duplication. Optimize. Create new abstractions. Refactoring is a key part of design, so donât skip this. Remember to run the tests ...
Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.