Given When Then = BDD Approach

Behaviour-Driven Development (BDD) emerged from Test-Driven Development (TDD) and Acceptance-Test Driven Developement (ATDD). BDD uses Given-When-Then style of representing test scenarios and application features . Each test scenarios consist of test steps which fall under Givens, Whens and Thens. We automate test fixtures and scenarios using Java, JavaScript and Groovy languages using BDD approach. Few BDD frameworks:

  • Spock framework
  • Cucumber JVM
  • Cucumber JS
  • JBehave framework
  • Given-When-Then:

    1. Given Step: puts the system or application in state before your test scenario starts. This is the pre-condition that the test need to meet. Examples:
      • Set up test database state by creating records, running sql scripts.
      • Perform application Login with required role. Move to a specific page in UI.
    2. When Step: performs specific system action that needs to be tested in the scenario. Examples:
      • User Interaction with a web page like clicking or form submit
      • Any UI actions that results a behavior.
      • Starting a job which result an observable behavior.
    3. Then Step: observes the outcome of the When actions. It describes the expected result due to the above steps. Examples:
      • Checking expected results on UI page
      • Verify Database state.
      • Verify external system state.
    4. And Step: several given, whens or thens in a scenario.
  • Example:

    Feature: User shopping check out
      Scenario: User successful Check out
        Given: user logger in
          And: user has billing and shipping details
          And: user on check out page
    
        When: user confirms on the shipping address
          And: user selects the payment details
          And: user performs the check out
    
        Then: application lands on confirmation page
          And: user should able to print the confirmation
    
  • Summary:

    • Given-When-Then steps represents system behavior testing. The basic idea is common while performing behavior testing of the system/application. Some times it will be tempting to implement Then steps to check directly in the database. But you should verify the expected results in the system with respect to user. (not checking the database as the database is not exposed to user.)
    • Specification tests with Given-When-Then style are more readable and maintainable.
    • KickStartPros uses Given-When-Then approach using BDD frameworks like Cucumber, JBehave and Spock for automation testing.
Let us know your BDD testing plans.

No comments :

Post a Comment