Defects are introduced when a person makes a mistake during the creation of a work product. This work product can be a requirements specification, a user story, a technical document, a test case, the program code, or any other work product produced during a software development or maintenance process.
Defects may be introduced at any point in the software development lifecycle and in any software- related work product. Therefore, each phase of the software development lifecycle should include activities to detect and remove potential defects. For example, static testing techniques (i.e., reviews and static analysis) can be used on design specifications, requirements specifications, and code prior to delivering those work products to subsequent activities. The earlier each defect is detected and removed, the lower the overall cost of quality for the system; the cost of quality for a given level of defects is minimized when each defect is removed in the same phase in which it was introduced (i.e., when the software process achieves perfect phase containment). Furthermore, static testing finds defects directly, rather than finding failures, and thus the cost of removing the defect is lower because debugging activities are not required to isolate the defect.
During dynamic testing activities such as unit testing, integration testing, and system testing, the presence of a defect is revealed when it causes a failure, which results in a discrepancy between the actual results and the expected results of a test (i.e., an anomaly). In some cases, a false-negative result occurs when the tester does not observe the anomaly. If the tester does observe the anomaly, a situation has occurred which requires further investigation. This investigation starts with the filing of a defect report.
In Test Driven Development, automated unit tests are used as a form of executable design specifications. As code is developed, it is immediately exercised using these tests. Until the development of the unit is complete, some or all of the tests will fail. Therefore, the failure of such a test does not constitute a defect, and is typically not tracked.