Failure, Defect, and Error Definitions
Failures, Defects and Errors
When software misbehaves, people often say "there is a bug" whether they mean a programmer's slip, a wrong line of code or a crash a customer reported. Testing needs sharper words, because each of these is found, counted and fixed in a different way. This lesson separates the human mistake, the flaw it leaves in a work product and the misbehaviour someone observes, and shows how to count them without mixing them up.
Three terms, one causal chain
The vocabulary used in IEEE standards and by the ISTQB describes a chain of cause and effect. A person makes an error, also called a mistake: a human action that produces an incorrect result, such as misreading a requirement. The error can leave a defect, also called a fault or bug: a flaw in code, a design or another work product that can make the system behave incorrectly. When the defective code runs under the right conditions, the system can produce a failure: an observable deviation of the delivered behaviour from what the requirements specify.
Term | Where it exists | Who usually finds it | Typical evidence |
|---|---|---|---|
Error | In a person's understanding or action | The developer, a reviewer | A misread requirement, a wrong assumption |
Defect | In a work product: code, design, specification | Code review, static analysis, debugging | A wrong operator, a missing check |
Failure | In the behaviour of the running system | Testers, users, monitoring | Wrong output, a crash, a missed deadline |
Example: A developer believes a language's arrays are indexed from 1, which is the error. The loop they write skips element 0, which is the defect. A sales report then leaves out the first sale of each day, and the accountant sees a wrong total, which is the failure.
A defect exists from the moment it is written, whether or not anyone has seen it misbehave; a defect that has not yet caused a failure is called a dormant defect. Failures can also come from outside the code, such as a hardware fault or a misconfigured server, but this lesson concerns failures caused by software defects.
Why a defect does not always cause a failure
A defect produces a failure only when three things happen in order:
- Execution: the program reaches the defective code.
- Corruption: running that code puts the program into a wrong internal state, such as a variable holding an incorrect value.
- Propagation: the wrong state reaches something observable, such as output, a stored record or a response time.
Example: The requirement says customers aged 18 or older may register, but the code reads if age > 18. An input of 25 executes the line, yet the comparison gives the same result as correct code, so the state is not corrupted. Only an input of exactly 18 corrupts the state, and that customer is wrongly refused. Corrupted state can also be masked: a wrong intermediate value that is overwritten before it is used never becomes a failure.
This chain is why passing tests show only that the inputs you ran did not fail. They do not show that the code is free of defects.
Counting defects and failures
One defect can cause many failures, so teams keep the two counts separate. Failure reports from testers and users are grouped by their underlying cause, and each distinct confirmed defect is counted once. A common size-normalised measure is defect density:
where size is measured in KLOC. Reports also undercount failures, because they record only the failures someone noticed and filed.
Example: Triage of 96 failure reports on a 24,000-line service traces them to 18 distinct defects. The size is 24 KLOC, so the defect density is 18/24=0.75 defects per KLOC, and each defect produced 96/18≈5.3 reports on average.
What to remember
- An error is a human mistake; a defect is the flaw it leaves in a work product; a failure is the observable wrong behaviour of the running system.
- A defect exists whether or not it has failed. It causes a failure only when execution reaches it, the state is corrupted and the corruption propagates.
- Passing tests do not prove the absence of defects.
- Count distinct defects separately from failures and failure reports; defect density is distinct defects per KLOC.
Example: Tracing a discount bug from mistake to overcharge
An online store's checkout module contains 12,500 lines of code. Its specification says that orders totalling $100.00 or more receive a 10% discount. The developer read this as "more than $100.00" and wrote:
def discounted_total(total):
if total > 100.00:
return round(total * 0.90, 2)
return totalIn the first week after release the store processed 2,400 orders, and every order passed through this function. Exactly 36 orders totalled $100.00; every other order total was at least one cent away from $100.00.
a) Identify the error, the defect and the failure in this situation.
Apply each definition to the place where it lives.
- Error: the developer's misreading of "or more" as "more than". It is a human action that produces an incorrect result, and it happens in the developer's understanding before any code exists.
- Defect: the comparison total > 100.00 in discounted_total, which should be total >= 100.00. It is a flaw in the work product, and it exists from the commit onward whether or not any order triggers it.
- Failure: each checkout in which a customer with a $100.00 order is charged $100.00 instead of the $90.00 the specification requires. This is the observable deviation of delivered behaviour from the requirement.
b) How many failures did the defect cause that week, and how much were customers overcharged in total?
Every order calls discounted_total, so the defective comparison was executed ________ times. Executing the line is not enough for a failure; the state must also be corrupted. Compare the code with the specification for each kind of total:
- Total below $100.00: both > and >= are false, so no discount is applied, which is correct.
- Total above $100.00: both are true, so the discount is applied, which is correct.
- Total exactly $100.00: the code gives false where the specification requires true, so the order keeps its full price and that wrong value is charged to the customer.
Only the 36 orders of exactly $100.00 corrupt the state, and the wrong total propagates directly to the amount charged, so each one is a failure. Only 36/2400 of the executions, or ________, failed.
For each affected order the specification requires 100.00×0.90=90.00 dollars, so each customer was overcharged ________. The total overcharge is
The single defect caused 36 failures that week, and customers were overcharged 360 dollars in total.
c) Over the first quarter after release, users and testers filed 54 failure reports against the checkout module. Triage traced them to 9 distinct defects, including the discount comparison. Find the module's defect density and the mean number of reports per defect.
Defect density uses distinct defects and size in thousands of lines. Converting the size, 12500/1000 gives ________. Then
Dividing the 54 reports by 12.5 KLOC would give 4.32 per KLOC, which counts failure reports rather than defects. Reports also record only the failures someone noticed and filed, so they can be far fewer than the failures that actually occurred, as the 36 overcharges in a single week suggest.
The defect density is 0.72 defects per KLOC, and each defect accounts for 6 reports on average.
A rewards application must award exactly 12 points per completed task. For three completed tasks, it displays 36 points. An automated test stores an expected result of 35 points and reports a mismatch. The approved requirement is unambiguous, and the displayed result is the only application behaviour being assessed.
Complete each statement using either defect or failure, using each word once.
The incorrect expected value stored in the test is a . Relative to the approved requirement, the application has demonstrated no in this run.
A backend developer believes a library's timeout argument is measured in seconds, when the library actually measures it in milliseconds. Put the following events in the order in which they occur, from the original mistake to the record of the problem.
1.
A user request runs the code path that passes the constant to the library.
2.
Support staff log a ticket describing the timeout message.
3.
A commit sets the timeout constant to 30 rather than 30000.
4.
The user's screen shows a timeout message instead of the requested page.
5.
The library abandons the connection after 30 ms, leaving the request incomplete in memory.
6.
The developer assumes the timeout argument is in seconds.