1 / 28

Behavior Driven Development Using Visual Studio 2010 And SpecFlow

Behavior Driven Development Using Visual Studio 2010 And SpecFlow. Ivan Pavlovi ć MVP Visual C#, Scrum Master hiv e -studios.com ivan.pavlovic@hive-studios.com Twitter: @ ipavlovi. Hive Studios. We Build Awesome Software Teams. What We Do? Scrum Coaching User Requirements

collin
Download Presentation

Behavior Driven Development Using Visual Studio 2010 And SpecFlow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Behavior Driven DevelopmentUsing Visual Studio 2010 AndSpecFlow Ivan Pavlović MVP Visual C#, Scrum Master hive-studios.com ivan.pavlovic@hive-studios.com Twitter: @ipavlovi

  2. Hive Studios We Build Awesome Software Teams What We Do? • Scrum Coaching • User Requirements • Team Empowerment • Solution Architecture • Software Quality • Build Automation How We Deliver? • On Site Training • Workshops • Long term Coaching

  3. Agenda • Back To Basics • What is Requirement • What is BDD? • Filling the gap • Language • Gherchin • Tools • SpecFlow, Visual Studio • Demos, common usage • Unit & Acceptance testing

  4. What Is Software Requirement • Actor - Who is performing an action • Action - What action? • Result - Why, who benefits? • Acceptance Criteria - How To Demo? • Additional Details • Priority This is bare minimum!

  5. Decomposition • Break down requirement into manageable chunks of work (1-2 days) • Developer is the most important end user of requirements in this stage • And I’ll say it again: Break down requirement into manageable chunks of work

  6. BehaviourDrivenDevelopment • One of many agile development techniques • Specification driven by examples • Clear 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/)

  7. Gherkin • DomainSpecificLanguage • Easy to understand by customers • Simple sintax, few keywords • Feature • Background • Scenario, Scenario Outline • Given,When, Then • Localized to 35+ languages

  8. Gherkin (sr-Latn) "sr-Latn": name: Serbian (Latin) native: Srpski (Latinica) feature: Funkcionalnost|Mogućnost|Mogucnost|Osobina background: Kontekst|Osnova|Pozadina scenario: Scenario|Primer scenario_outline: Strukturascenarija|Skica|Koncept examples: Primeri|Scenariji given: "*|Zadato|Zadate|Zatati" when: "*|Kada|Kad" then: "*|Onda" and: "*|I" but: "*|Ali"

  9. Gherkin (sr-Cyrl) "sr-Cyrl": name: Serbian native: Српски feature: Функционалност|Могућност|Особина background: Контекст|Основа|Позадина scenario: Сценарио|Пример scenario_outline: Структура сценарија|Скица|Концепт examples: Примери|Сценарији given: "*|Задато|Задате|Задати" when: "*|Када|Кад" then: "*|Онда" and: "*|И" but: "*|Али"

  10. Real example Feature: 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

  11. Tools • SpecFlow– .NET, http://specflow.org • Nunit, MSTest, MBUnit… • Integrates into Visual Studio DevEnv • Users are writing *.feature files • Tool translates specs into *.feature.cs files • Inspired by Cucumber – Rubyhttp://cukes.info/

  12. Supported Test Types • Unit testing • Acceptance / Customer testing • Integration testing • Performance testing • Regression testing • ...

  13. Unit Test Example Demo 1 > Hello World Demo

  14. Putting All The Pieces Together • User writes features & scenarios, clarify • SpecFlow generates one test per scenario • Developer runs test • Developer implements missing steps • Developer writes production code • Move to the next scenario

  15. What Does SpecFlow Do?

  16. Mapping Step Definitions … 7: Given some precondition 8: And some other precondition 9: When some action by the actor 10: Thensome 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

  17. Step Arguments - RegEx … 7: GivenI have 5 apples 8: AndI eat 2 of them 9: Whensomeone asks how many apples I do have 10: Then I should answer “3 apples” [Given(@„I have (.*) apples")] public void SomePrecondition(intnumberOfApples) { … do something… } [Given(@„ I eat (.*) of them")] public void SomePrecondition(intnumberOfEatenApples) { … 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 … }

  18. DEMO Demo 2 > Step Arguments

  19. Scenario outline - refactoring Scenario: TC1 Add two numbers Given I have entered 1 into the calculator And I have entered 2 into the calculator When I press add Then the result should be 3 on the screen Scenario: TC2 Add two numbers GivenI have entered 2 into the calculator AndI have entered 2 into the calculator WhenI press add Thenthe result should be 4 on the screen

  20. Scenario outline - refactoring Scenario Outline: TC5GivenI have entered <x> into the calculatorAndI have entered <y> into the calculatorWhenI press addThenthe result should be <result> on the screenScenarios: addition| x | y | result|| 1 | 2 | 3 || 2 | 2 | 4 | | 3 | -3 | 0 |

  21. DEMO Demo 3 > Scenario outline

  22. Table Parameters Scenario: Posting a validentry Given I am on the postingpage And I havefilledout the form as follows | Label | Value | | Yourname | Jakob | | Yourcomment | Das ist gut! | WhenI click the buttonlabelled "Post" ThenI should be on the guestbookpage Andthe guestbookentriesincludes the following | Name | Comment | Posted date | | Jakob | Das ist gut! | (within last minute) | [Given(@"I havefilledout the form as follows")] publicvoidFillFormAsFollows(TechTalk.SpecFlow.Tabletable) { foreach(var row in table.Rows) { ….. Do something … } }

  23. DEMO Demo 4 > Table parameters

  24. How to Implement Step Definitions? • It’s up to you – depends on what you are testing • Public Interfaces / Components • Unit or integration testings • WebUIusingbrowserautomation • WatiN, Selenium • WebUIusingRequest/Respons • Http Get/Post • Win UI usingautomation • White / Windows UI Automation

  25. WPF UI Automation using White Demo 5 > Acceptance Testing

  26. Key Points • You can and you should automate tests now • Win, WFP, Web, Silverlight, Service, Phone Apps • Break down requirements until you can express them in Gherkin, in your own language • Threat tests as first-class citizens, refactor often • Pay attention to the test setups and dependencies

  27. Resources • Specflow • http://specflow.org • Gherkin • https://github.com/cucumber/cucumber/wiki/Gherkin • White • http://white.codeplex.com/ • WatiN • http://watiN.sourceforge.net

  28. Thank You! See you on Sinergija 11! Ivan Pavlović MVP Visual C#, Scrum Master hive-studios.com ivan.pavlovic@hive-studios.com Twitter: @ipavlovi

More Related