Given-When-Then
{{Short description|A semi-structured way to write down test cases used for testing in software development}}
{{Use dmy dates|date=April 2018}}
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.{{Cite book |last=Percival |first=Harry |url=https://books.google.com/books?id=fTLJAwAAQBAJ&dq=GivenWhenThen+Selenium&pg=PA437 |title=Test-Driven Development with Python: Obey the Testing Goat: Using Django, Selenium, and JavaScript |date=2014-06-11 |publisher="O'Reilly Media, Inc." |isbn=978-1-4493-6517-2 |language=en}}{{Cite book |last=Pugh |first=Ken |url=https://books.google.com/books?id=tB23eWcG9DEC&dq=GivenWhenThen+Selenium&pg=PT432 |title=Lean-Agile Acceptance Test-Driven Development: Better Software Through Collaboration |date=2010-12-22 |publisher=Pearson Education |isbn=978-0-321-71944-7 |language=en}}
It derives its name from the three clauses used, which start with the words given, when and then.{{cite web|url=http://www.jroller.com/perryn/entry/given_when_then_and_how|title=Perryn Fowler's Weblog|last=Fowler|first=Perryn|date=24 November 2009|accessdate=14 August 2014|archive-url=https://archive.today/20140814232159/http://www.jroller.com/perryn/entry/given_when_then_and_how|archive-date=14 August 2014|url-status=dead}} 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.{{cite web|url=http://ebgconsulting.com/blog/using-given-when-then-to-discover-and-validate-requirements-2/|title=Using "Given-When-Then" to Discover and Validate Requirements|last=Gorman|first=Mary|author2=Ellen Gottesdiener |date=9 December 2012|accessdate=14 August 2014}}