Oct-13-2019, 02:29 PM
I start by writing a failing test. That is, I write an automated test (e.g. a unit test) that expresses, in code, what should happen in a scenario I want to implement. In so doing, I'm focused on one small part of the problem (i.e. a particular scenario) and think about things needed to make it work (like any input data, or system state). I then run the test to make sure it fails (which it should, because there isn't an implementation yet) and then write enough of an implementation to make it pass. Once it's passing, I perform any necessary refactoring (extracting methods, putting parts of the code in the right place, making sure names are as expressive as they should be).
This "red, green, refactor" cycle is known as test-driven development (TDD).
This "red, green, refactor" cycle is known as test-driven development (TDD).