In this section, you will learn to write tests that fail. Then you will learn to write just enough code to make the test pass, and then if necessary, you will perform any refactoring that needs to take place.
Before we delve into a practical example of TDD, let's consider why we need TDD. In the previous section, you saw how we can create feature files and generate step files from them to write code that meets a business need. Another way to ensure that your code meets the business requirements is with TDD. With TDD, you start with a test that fails. Then, you write just enough code to make the test pass, and as the need arises, you perform refactoring of your new code. This process is repeated until such time as all the features have been coded.
But why do we need TDD?
Business software specifications are put together by business analysts who work with project stakeholders to design new software...