Given-When-Then - Applied BDD

Avi Santoso

Behavior-Driven Development (BDD) is an approach aimed at improving collaboration and clarity by defining requirements through concrete examples of system behavior. The most common technique associated with it is the Given-When-Then (GWT) syntax, often used for writing Acceptance Criteria.

The structure is straightforward:

  • Given: Sets the initial context or state. (e.g., "Given the shopping cart contains Product X").
  • When: Describes the action or event triggered. (e.g., "When the user clicks 'Proceed to Checkout'").
  • Then: Specifies the expected, verifiable outcome. (e.g., "Then the order summary page is displayed").

For estimation, GWT is incredibly useful. It forces the breakdown of a user story into specific, distinct scenarios (happy paths, error conditions, edge cases). Instead of estimating one abstract feature, you implicitly consider the effort for each GWT scenario defined in the ACs. This granularity makes estimation discussions more concrete. We can talk about the complexity of implementing the 'Given' setup, handling the 'When' action, and achieving the 'Then' outcomes for each scenario.

Another reason I love GWTs is that they are directly translatable to unit tests. They are directly analogous to the Arrange, Act, and Assert (AAA) pattern used in unit testing. They are also directly translatable to integration tests, as many BDD frameworks use the Gherkin syntax.

While BDD specialists focus on the full testing and collaboration cycle, for engineers involved in estimation, GWT provides a powerful structure for dissecting requirements into estimable behavioral chunks, significantly reducing ambiguity around what needs to be built.

Recent Posts