Software Development and Project Management
Which describes how test-driven development (TDD) proceeds?
- AWrite a test that does not yet pass, write the minimum code to make it pass, and then refactor while keeping the tests passing
- BFinish writing all the code for a feature, then create test cases by following the branches in that code
- CDedicated testers write the tests, and developers do not run any tests until the integration testing stage
Show answer and explanation
Answer: A. Write a test that does not yet pass, write the minimum code to make it pass, and then refactor while keeping the tests passing
In test-driven development, a small piece of the specification of the feature to be built is first written as a test, which is run to confirm that it fails (red). Next, the minimum code needed to pass that test is written (green), and then duplication and other problems are cleaned up while the tests keep passing (refactor). Through this short cycle, features are added little by little while a full set of tests is maintained. In embedded firmware too, the hardware-dependent parts are made replaceable so that unit tests can be run repeatedly on a development PC.
- A. Correct. The cycle of red (a failing test), green (the minimum code to pass) and refactor is repeated.
- B. This is the traditional order of writing code first and tests afterwards. In test-driven development the tests are written first.
- C. In test-driven development, developers run the tests they wrote themselves every time they write code.
Continue: 9 more Software Development and Project Management questions