Behavior Driven Development (Brief Understanding)

Behavior Driven Development is the way for software teams to make effective interactions between business and technical personnel.

The goal of BDD is that allows to describe an application’s behavior without involving development technicalities and designed an effective procedure to assistance the business stakeholders and the software technical team and Improves communication between stakeholders.

This structure allows a bridge between Programming language and Natural Language. It has  plus points like test scripts can be written in any locale used by the stakeholders like English, French, Spanish etc.

No alt text provided for this image

Gherkin is the structured normal language that is used by any stakeholder to specify how they want the system to behave for given scenarios. It uses more about 10 keywords (Given, When, Then, And, But, Scenario, Feature, Background, Scenario Outline, Examples) which allow the language to be read and parsed by a tool called Cucumber. Every Cucumber project consist of Feature and Step Definition files

Features file contain high level description of the Scenario in Gherkin.

It consists of following steps to use Gherkin syntax:

Start User stories.

  • FEATURE: Business Need
  • SCENARIO: Test case / Business Case Title
  • GIVEN is your setup
  • WHEN is your action
  • THEN is your assertion

Automate your BDD scenarios.

  • First execution will fail as the feature is not yet implemented

Implement the feature

Run the automated BDD scenarios to show the feature is completed

Example of Feature file

Feature: The sum of two numbers

 

Scenario: Add two numbers

                Given I have entered 250 into the calculator

                And I have entered 70 into the calculator

                When I press add

                Then the result should be 320 on the screen                  

Step definition maps the Test case / Business Case Steps in the feature files to code.

 Example of Step file

public class StepDefinitions

        {

            [Given(@"I have entered (.*) into the calculator")]

            public void GivenIHaveEnteredIntoTheCalculator(int num)

            {

            Console.WriteLine(num);

            }

 

            [When(@"I press add")]

            public void WhenIPressAdd()

            {

            Console.WriteLine("Add");

            }

 

            [Then(@"the result should be (.*) on the screen")]

            public void ThenTheResultShouldBeOnTheScreen(int outcome)

            {

            if (outcome == 320)

                Console.WriteLine("Passed");

            else

            {

                Console.WriteLine("Failed");

                throw new Exception("Failed with Exception");

            }

            }

        }        }

  Conclusion:

BDD is a great way to improve clarity and collaboration within the team, it improves the quality of the application and removes barriers of communication between tech and non tech personnel

Upcoming SPECFLOW !!!!!


要查看或添加评论,请登录

Muhammad Kamran ?的更多文章

  • Role of the Scrum Framework in Machine Learning Projects

    Role of the Scrum Framework in Machine Learning Projects

    In the fast-changing field of machine learning, projects can be tough to manage because they are complicated and hard…

  • Psychology in Software Testing

    Psychology in Software Testing

    Human psychology has significant impact on software testing because Software development, involving software testing…

    1 条评论
  • Overview to Scaled Agile

    Overview to Scaled Agile

    Scaled Agile: Scaled Agile is designed to give a team flexibility and it includes set of Lean Agile Principles…

    2 条评论

社区洞察

其他会员也浏览了