Test-driven development

Test-driven development is a software development process where the process of software development involves the writing of tests for the individual requirements first, and then building or improving methods that will pass those tests. This kind of process usually benefits in terms of producing an application with a smaller number of defects than it would have if the tests would have been written once the components were developed.

During test-driven development, the following steps are followed:

  1. Add a test: Once the requirements are specified, the developers start by writing a new test for a new component of improvement in the previous component. This test sets the expected outcome from the particular component.
  2. Run the tests to see if the new test fails: When the new test has been added, the tests are run against the code to see if the new test fails for the expected reasons. This assures us that the test works as expected and does not pass in unfavorable conditions.
  3. Write/modify the component: Once the tests have been run and an expected result can be seen, we move on to either writing the new component or modifying the existing component so that the newly added test case passes.
  4. Run tests: Once the required modification has been made for the test to pass, the test suite is made to run again to see if the previously failing test now passes or not. This assures that the modifications are working as expected.
  5. Refactor: As we progress in the development life cycle of the application following the TDD process, there will be times when there will be tests that will be duplicated or components that might be playing the same responsibility. To remove these issues, constant refactoring is required so as to reduce the duplication.

Now, we have quite an understanding about how much the testing plays an important role in the development of any successful application, and also about how to write code that can be tested easily. Now, it's time for us to get our hands dirty and start writing some tests for the application that we built in chapter 6, Example – Building BugZot.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.35.255