Top Banner
© Hive Studios 2011 Behavior Driven Development Using Visual Studio 2010 And SpecFlow Ivan Pavlović, Hive Studios Visual C# MVP, MCT, CSM [email protected] http://msforge.net/blogs/paki http://twitter.com/ipavlovi
16

Behavior Driven Development Using Visual Studio 2010 And SpecFlow

Feb 23, 2016

Download

Documents

olive

Behavior Driven Development Using Visual Studio 2010 And SpecFlow. Ivan Pavlovi ć, Hive Studios Visual C# MVP, MCT , CSM [email protected] http://msforge.net/blogs/paki http://twitter.com/ipavlovi. Agenda. Little bit of s lides , a lot of examples What is BDD Language Tools - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

Behavior Driven DevelopmentUsing Visual Studio 2010 AndSpecFlow

Ivan Pavlović, Hive StudiosVisual C# MVP, MCT, [email protected] http://msforge.net/blogs/pakihttp://twitter.com/ipavlovi

Page 2: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

2

AgendaLittle bit of slides, a lot of examples

What is BDDLanguageToolsDemos

Page 3: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

3

Types of TestUnit testingAcceptance / Customer testingIntegration testingPerformance testingRegression testing

Page 4: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

4

Behaviour Driven DevelopmentOne of agile development techniques

Specification driven by examplesClear communication between domain experts, developers, testers and customers

BDD is a second-generation, outside-in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters. - Dan North (http://dannorth.net/)

Page 5: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

5

GherkinDomain Specific LanguageEasy to understand by customersSimple sintax, few keywords

FeatureBackgroundScenario, Scenario OutlineGiven, When, Then

Localized on 35+ languages

Page 6: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

6

Example 1: Feature: Some descriptive text of what is desired 2: In order to realize a named business value 3: As an explicit system actor 4: I want to gain some beneficial outcome which furthers the goal 5: 6: Scenario: Some determinable business situation 7: Given some precondition 8: And some other precondition 9: When some action by the actor10: And some other action11: And yet another action12: Then some testable outcome is achieved13: And something else we can check happens too14: 15: Scenario: A different situation16: ...

Page 7: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

7

Real exampleFeature: Serve coffee In order to earn money Customers should be able to buy coffee at all times

Scenario: Buy last coffee Given there are 1 coffees left in the machine And I have deposited 1$ When I press the coffee button Then I should be served a coffee

Page 8: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

8

ToolsTools are generating *.feature files

Cucumber – Ruby, http://cukes.info/

SpecFlow – .NET, http://specflow.orgNunit, MSTest, MBUnit…

…a lot of other tools

Page 9: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

9

Putting All The Pieces Together1. User writes features & scenarios, clarify2. SpecFlow generates one test per scenario3. Developer runs test4. Developer implements missing steps5. Developer writes production code6. Move to the next scenario

Page 10: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

10

Mapping Step Definitions… 7: Given some precondition 8: And some other precondition 9: When some action by the actor10: Then some testable outcome is achieved

[Given(@„some precondition")]public void SomePrecondition() { … do something… }

[Given(@„some other precondition")]public void SomePrecondition() { … do something… }

[When(@„some action by the actor")]public void SomePrecondition() { … do something… }

[Then(@”some verifiable result”)]Public void VerifyResult() { … do assert… }

TEST RUN

Page 11: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

11

Step Arguments - RegEx… 7: Given I have 5 apples 8: And I eat 2 of them 9: When someone asks how many apples I do have 10: Then I should answer “3 apples”[Given(@„I have (.*) apples")]public void SomePrecondition(int numberOfApples) { … do something… }

[Given(@„ I eat (.*) of them")]public void SomePrecondition(int numberOfEatenApples) { … do something… }

[When(@„ someone asks how many apples I do have")]public void SomePrecondition() { … do something… }

[Then(@” I should answer \“(.*) apples\””)]Public void VerifyResult(int expected) { … do assert of expected … }

Page 12: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

12

Scenario: Posting a valid entry Given I am on the posting page And I have filled out the form as follows | Label | Value | | Your name | Jakob | | Your comment | Das ist gut! | When I click the button labelled "Post" Then I should be on the guestbook page And the guestbook entries includes the following | Name | Comment | Posted date | | Jakob | Das ist gut! | (within last minute) |

Table Parameters

[Given(@"I have filled out the form as follows")]public void FillFormAsFollows(TechTalk.SpecFlow.Table table) { foreach (var row in table.Rows) { ….. Do something … }}

Page 13: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

13

Scenario outline - refactoringScenario: TC1 Add two numbersGiven I have entered 1 into the calculatorAnd I have entered 2 into the calculatorWhen I press addThen the result should be 3 on the screen

Scenario: TC2 Add two numbersGiven I have entered 2 into the calculatorAnd I have entered 2 into the calculatorWhen I press addThen the result should be 4 on the screen

Page 14: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

14

Scenario outline - refactoringScenario Outline: TC5Given I have entered <x> into the calculatorAnd I have entered <y> into the calculatorWhen I press addThen the result should be <result> on the screen

Scenarios: addition| x | y | result|| 1 | 2 | 3 || 2 | 2 | 4 || 3 | -3 | 0 |

Page 15: Behavior Driven Development Using Visual Studio  2010 And SpecFlow

© Hive Studios 2011

15

How to Implement Step Definitions?

It’s up to you!What you are testing?

1. Public Interfaces / Components2. WebUI using browser automation

• WatiN, Selenium3. WebUI using Request/Respons

• Http Get/Post4. Win UI using automation

• White / Windows UI Automation