Article · Wikipedia archive · Last revised May 30, 2026

Given-When-Then

Given-When-Then (GWT) is a semi-structured way to write down test cases. They can either be tested manually or automated as browser tests with tools like Selenium and Cucumber.

Last revised
May 30, 2026
Read time
≈ 1 min
Length
282 w
Citations
4
Source

Given-When-Then (GWT) is a semi-structured way to write down test cases. They can either be tested manually or automated as browser tests with tools like Selenium and Cucumber.12

It derives its name from the three clauses used, which start with the words given, when and then.3 Given describes the preconditions and initial state before the start of a test and allows for any pre-test setup that may occur. When describes actions taken by a user during a test. Then describes the outcome resulting from actions taken in the when clause.

The Given-When-Then was proposed by Dan North in 2006, as part of behavior-driven development.4

Example

A Given-When-Then test case for a hypothetical inventory software could be structured as follows:

GIVEN that the inventory contains 10 units of steel
    AND the inventory contains 30 units of copper
WHEN we consume 2 units of steel
    AND we consume 10 units of copper
    AND we purchase 5 units of steel
THEN the inventory should contain 13 units of steel
    AND the inventory should contain 20 units of copper
    AND the purchase of 5 units of steel should be registered in the expenses list
See also

See also

References

References

  1. Percival, Harry (11 June 2014). Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript. O'Reilly Media, Inc. ISBN 978-1-4493-6517-2.
  2. Pugh, Ken (22 December 2010). Lean-Agile Acceptance Test-Driven Development: Better Software Through Collaboration. Pearson Education. ISBN 978-0-321-71944-7.
  3. Fowler, Perryn (24 November 2009). "Perryn Fowler's Weblog". Retrieved 14 August 2014.{{cite web}}: CS1 maint: deprecated archival service (link)
  4. Gorman, Mary; Ellen Gottesdiener (9 December 2012). "Using "Given-When-Then" to Discover and Validate Requirements". Retrieved 14 August 2014.