Saturday, February 25, 2017

BDD - Quick Start Guide

Behavior-driven development (BDD) is a software development methodology in which an application is specified and designed by describing how its behavior should appear to an outside observer. 

Principles of BDD: -
  • First define a test set for the unit/module
  • Make the test fail
  • Then implement the failed unit
  • Finally verify that the implementation of the unit makes the tests success
Concepts to Remember: -
  • Keywords:
    • Feature: List of scenarios.
    • Scenario: Business rule through list of steps with arguments.
    • Given: Some precondition step
    • When: Some key actions
    • Then: To observe outcomes or validation
    • And, But: To enumerate more Given, When, Then steps. But is mainly used for negative scenarios
    • Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
    • Examples: Container for s table
    • Background: List of steps run before each of the scenarios
  • Symbols:
    • """ (Doc Strings)
    • | (Data Tables)
    • @ (Tags/Labels): To group Scenarios 
    • <> (placeholder)
    • "" (scenario parameter container)
    • # (Comments)

  • Feature File Definition Template: -
        @tag
          Feature: Title of your feature
                  I want to use this template for my feature file

          @tag1
          Scenario: Title of your scenario
          Given I want to write a step with precondition
             And some other precondition
          When I complete action
             And some other action
             And yet another action
          Then I validate the outcomes
          And check more outcomes

         @tag2
          Scenario Outline: Title of your scenario outline
          Given I want to write a step with <name>
          When I check for the <value> in step
          Then I verify the <status> in step

          Examples:
          | name    |value | status |
          | name1  |  5       | success|
          | name2    7   | Fail   |

  • Step Definition: -  When Cucumber executes a Step in a Scenario it will look for a matching Step Definition to execute. A Step Definition is a small piece of code with a pattern attached to it. The pattern is used to link the step definition to all the matching Steps, and the code is what Cucumber will execute when it sees a Gherkin Step.
    • Example: - Using Java & Cucumber


  • Runner File: - Mainly it's the driver to drive whole test execution.
    • Options: -
      • -g, --glue PATH -Where glue code (step definitions and hooks) is loaded from.
      • -f, --format FORMAT[:PATH_OR_URL]  How to format results. Goes to STDOUT unless PATH_OR_URL is specified. Built-in FORMAT types: junit, html, pretty, progress, json. FORMAT can also be a fully qualified class name.
      • -t, --tags TAG_EXPRESSION - Only run scenarios tagged with tags matching TAG_EXPRESSION.
      • -n, --name REGEXP - Only run scenarios whose names match REGEXP.
      •  -d, --[no-]-dry-run - Skip execution of glue code.
      • -m, --[no-]-monochrome - Don't colour terminal output.
      • -s, --[no-]-strict - Treat undefined and pending steps as errors.
      • --dotcucumber PATH_OR_URL-Where to write out runtime information. PATH_OR_URL can be a file system path or a URL
      • -v, --version - Print version.
      • -h, --help - You're looking at 
    • Example: - Using Java & Cucumber


Market Leading Tools: -
  • Cucumber: - https://cucumber.io/
  • JBehave: - http://jbehave.org/
  • SpecFlow:- http://specflow.org/
  • Serenity: - http://www.thucydides.info/#/
  • Spinach: - http://www.rubydoc.info/github/codegram/spinach/master




No comments: