Defect prevention

Defect prevention is the set of activities that stop defects from being introduced into software, instead of finding them once they are there. It works on the causes of mistakes: unclear requirements, missing review steps, error-prone code patterns and process gaps. Reviews, static analysis, agreed standards and root cause analysis fed back into the process are its main tools.

The longer version

Detection and prevention answer different questions. Detection asks what is wrong with this build. Prevention asks why builds keep arriving with this kind of fault, and changes the conditions that produce it. In the vocabulary of quality assurance and quality control, prevention is the assurance side and detection the control side. The ISTQB glossary defines defect prevention as the measures that reduce the likelihood of recurrence of defects in work products and limit the propagation of defects in subsequent work products. Both halves matter. Recurrence is the same mistake made again next month. Propagation is one mistake copied forward: an ambiguous requirement becomes a wrong design, the design becomes wrong code, and the code is covered by tests that faithfully confirm the wrong behaviour. The same body's Foundation Level syllabus, version 4.0.1, makes the point in its principle that early testing saves time and money: defects removed early in the process will not cause subsequent defects in derived work products.

The activities are easiest to list by where a mistake enters. Requirements are the first place, and nothing has been built on the error yet. A story is discussed from a business, a development and a testing perspective before work starts, acceptance criteria are written as concrete examples, and a requirement nobody can say how to test is sent back. In design and code, part of prevention is static testing, the reviews and automated analysis that examine a work product without running it. A review that catches a flaw in a pull request detects a defect in the code and prevents one in the product. Pair programming moves that review to the moment of writing, and test-driven development makes the expected behaviour explicit before any code exists. Prevention also includes things that are not testing at all: a type system or a linter that makes a class of mistake impossible to commit, coding standards, shared components that replace repeated hand-written logic, checklists for risky operations, and training in the area where a team keeps slipping.

The loop that makes prevention more than good intentions runs from the defects a team does find back to its process. It depends on a defect log that records, for each fault, what kind it is and the phase where it was found, because a team cannot see a pattern in defects it fixed without writing them down. Sorting the log by category, a Pareto view, shows which few kinds account for most of the defects and so where to start. Each significant defect of that kind is traced to its root cause, and the five whys and the fishbone diagram are two techniques for getting there. The cause is then removed in a way that outlasts the people who were in the room: a new lint rule, an added line in the definition of ready, a test data set, a changed review checklist. Fixing the bug closes one ticket, and changing the rule closes the category. Prevention has limits worth stating. Its effect cannot be seen directly, since a defect that never existed leaves no record, so it is read from trends such as fewer defects of a known class or lower defect leakage. Nor does it replace testing. Some defects arise from interactions nobody could foresee at a desk, and only running the software finds them.

Common questions

What is defect prevention in software testing?

Defect prevention in software testing is the work of stopping defects from being created, by removing the causes of mistakes in requirements, design, code and process. The ISTQB glossary describes it as measures that reduce the likelihood that defects recur and limit their propagation into later work products. Testing finds defects, and prevention lowers the number there are to find.

What is the difference between defect prevention and defect detection?

Defect detection finds faults that already exist, through reviews, analysis and testing, so that they can be fixed. Defect prevention changes how the work is done so that fewer faults are made. A failed test is detection. A rule added afterwards so that the same mistake cannot be merged again is prevention.

What are examples of defect prevention techniques?

Examples include reviewing requirements before design begins, writing acceptance criteria as testable examples, code review, static analysis and type checking in the pipeline, coding standards, reusable components, checklists for risky changes, training, and root cause analysis whose findings change the process. Each one acts before a defect reaches a running build.

Who is responsible for defect prevention?

Responsibility sits with everyone who produces a work product, since prevention acts where mistakes are made: analysts on requirements, designers on designs, developers on code. Someone also has to own the loop that turns root causes into process changes and checks that the changes hold, and a QA lead or an engineering manager is the natural holder. Testers contribute by reviewing requirements early and by classifying the defects they find.

How do you measure defect prevention?

Prevention is measured indirectly, because a prevented defect leaves nothing to count. Useful signs are a falling number of defects in a class that a process change targeted, fewer defects per release for work of similar size, lower defect leakage from each phase, and fewer reopened fixes. A comparison means something only when defects are logged as carefully after the change as before it.

How does defect prevention fit into defect management?

Defect management handles the defects that exist: logging, triage, fixing, verifying and closing each one. Defect prevention starts where that record ends. It reads the closed defects for patterns, finds the causes behind the most frequent kinds and changes the process, so that the next release has fewer defects for the management process to handle.

Bug reports that arrive ready to triage.

Collect replay, console, network and browser context with the Free plan.

<script src="…/widget.js" data-key="pb_pub_…">