Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Manual Testing  ›  Lesson

TDD, BDD and ATDD

TDD 15 minTest-driven development writes a failing unit test before the code, behaviour-driven development describes behaviour as shared Given-When-Then examples, and acceptance-test-driven development agrees the acceptance tests before building a feature.

TDD, BDD and ATDD

Remember the SAVE10 bug from lesson one: 10% off even below ₹500. Suppose that before any code was written, someone had written down "Given a ₹499 cart, when I apply SAVE10, then the total stays ₹499." The bug would have had nowhere to hide. Three related practices turn that idea into a habit.

The rule

Write the test first; let the test describe the behaviour.

TDD (test-driven development) is a developer's rhythm at the unit level, called red, green, refactor:

  1. Red: write a small unit test for behaviour that does not exist yet. It fails.
  2. Green: write just enough code to make it pass.
  3. Refactor: tidy the code, keeping the tests green.

BDD (behaviour-driven development) describes behaviour as concrete examples in plain language that business people, testers and developers all read, usually in the Given / When / Then style (often written in a format called Gherkin):

Scenario: SAVE10 does not apply below the minimum
  Given my cart subtotal is ₹499
  When I apply the coupon SAVE10
  Then my total is ₹499
  And I see "SAVE10 needs a cart of ₹500 or more"

Tools can link each line to automation code, so the same example becomes an executable test.

ATDD (acceptance-test-driven development) puts the team, typically product owner, tester and developer (sometimes called the "three amigos"), together before development to agree the acceptance tests for a story. The story is done when those tests pass.

The shortcut

Tell them apart by who writes what, at what size. One developer, one unit test: TDD. Everyone, plain-language behaviour examples: BDD. The team agreeing a story's acceptance tests before building: ATDD. BDD and ATDD overlap a lot; BDD stresses the shared language, ATDD the agreement.

SAVE10, test firstStep 1 of 4
  1. ATDD: agree the tests

    Owner, tester and developer agree: ₹500 gets 10% off, ₹499 gets none, expired coupons are refused.

The trap is writing the tests after the code and calling it TDD. The value comes from the test shaping the code and the conversation, not from the test existing.

Drills

Answer fast — trust the rule.

quick drill

What is the correct order of the TDD cycle?

quick drill

Which format is typical for BDD scenarios?

quick drill

Product owner, tester and developer agree acceptance tests before a story starts. Which practice?

quick drill

In TDD, why must the new test fail first?

Remember

  • Write the test first; let the test describe the behaviour.
  • TDD: developer, unit, red-green-refactor. BDD: shared Given/When/Then. ATDD: team agrees acceptance tests first.
  • Tests written after the code are not TDD.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainExamples before code

Write two Given/When/Then scenarios for the SAVE10 coupon (10% off carts of ₹500 or more), one where the discount applies and one where it does not. Then explain how TDD, BDD and ATDD differ in who writes tests and when.