QA
FresherTesting FundamentalsFree question

What is the difference between an error, a defect, a bug and a failure?

60-second answer

An error, or mistake, is a human action that produces a wrong result, like a developer misreading a requirement. That mistake introduces a defect, a flaw in the code or document. Bug is the informal name for a defect. When the defective code is executed and the system doesn't do what it should, that's a failure, which is what the user sees. So the chain is: error leads to defect, defect leads to failure. Not every defect causes a failure, because the code path might never run.

Explanation

  • Error / mistake: made by a person.
  • Defect / bug / fault: the result of the mistake, sitting in the code or the requirements.
  • Failure: the observable deviation from expected behaviour at run time.

Two useful points to add:

  1. A defect may never cause a failure if the condition is never met (for example, a bug in leap-year logic only fails on 29 Feb).
  2. Failures can also come from the environment, such as a full disk or a network outage, without a code defect.

Example

A developer writes if (age > 18) instead of if (age >= 18) (error). The code now has a defect. When an 18-year-old tries to sign up and is rejected, that's the failure.

Sample code

// Requirement: users aged 18 or older can register.
boolean canRegister(int age) {
    return age > 18;   // DEFECT: should be age >= 18
}

// Failure only shows up for the boundary value:
canRegister(25); // true  (looks fine)
canRegister(18); // false (failure seen by the user)