User Tools

Site Tools


given_when_then

Sources:

  1. Software Testing course at ITMO university by Kochubeev Nikolay Sergeevich

Given When Then (GWT)

GWT is an approach to tests and scenarios which comes from BDD (Behavior-Driven Development). It helps testers, analysts and for businesses.

GWT is made up of 3 parts:

  1. Given: the context: pre-conditions for the behavior.
  2. When: the behavior being described.
  3. Then: the changes expected due to the behavior.

Given

  • Is a description of the prerequisites of the test.
  • Creates the desired system state.
  • Is formulated in the language of the subject area.

When

  • A description of one key action.
  • It should be clear which trigger is being checked.

Then

  • Description of the expected result.
  • The focus is on the observed behavior, not the implementation.

Comparing AAA and GWT

AAA and GWT are very similar:

  • Arrange = Given.
  • Act = When.
  • Assert = Then.

AAA is used in testing code, and GWT is used in BDD scenarios, where it's important for them to be readable for the business.

Best practices

  1. Each test is one scenario.
  2. Formulate Given/When/Then in terms of the subject area, not the implementation.
  3. Use the following method names: Given_X_When_Y_Then_Z.
  4. Avoid “and” in the sections — this is a sign that the test is too difficult.
given_when_then.txt · Last modified: by plida