Introduce and Test New Functionality
2 minute read
The Change
When writing new functionality, write it directly into the test method that verifies it — not into the product code! This is a stick-figure test.
The Value Proposition
One of the hardest parts of TDD is to write the test first. Writing a test requires understanding the problem that the developer is trying to solve, whereas writing the product code requires understanding the solution. Very often developer see a solution so they write that solution without really understanding the problem they are solving. This reduces the tests to simplistic assertions about what their code just did. That eliminates most of the value of a unit test!
Writing all new functionality directly into the test method — making a stick-figure test — makes it easier for the developer to think about the problem as they are working on the solution.
That improves the value of your unit testing in the following ways:
- Elaborates detailed requirements before you write the code.
- Aligns coders with non-coders on those product requirements, independent of the solution.
- Reduces time it takes to develop new features.
- Creates unit tests that survive refactoring because they are independent of the solution.
Please log in
This content is only available to students. Please log in to access it.