Smallest Possible Increment

Learn the importance of adding small increments in the TDD cycle.

We'll cover the following

For each failing test, we should seek to add only the code needed to pass the test so that we add the smallest possible increment.

The mentality

The mentality behind this is to build code exactly to the “specifications” that the test represents. If all the tests pass, we could potentially ship the code since the tests document what the system does, no more, no less. With this, we avoid the potential waste of speculative development.

More practically (in terms of following the TDD cycle), writing the smallest amount of code means that, in most cases, we can write another test that will first fail.

Writing more code than needed means we could find ourselves writing lots of tests that pass immediately.

That might seem like a good thing, but it takes us right back to the old habit of slapping out lots of code before getting pertinent feedback. We’d rather know sooner that we have coded a defect.

The next-simplest case that comes to minds is that the profile should match when it contains an Answer matching that of the Criterion:

Get hands-on with 1000+ tech skills courses.

Learn to code, grow your skills, and succeed in your tech interview