1 / 29

Acceptance Test Driven Development with SpecFlow and Friends

Acceptance Test Driven Development with SpecFlow and Friends. Christopher Bartling Joel Levandoski. Contact information. Christopher Bartling chris.bartling@gmail.com Twitter: @cbartling Joel Levandoski joel.levandoski@gmail.com Twitter: @joellevandoski. Topics.

damita
Télécharger la présentation

Acceptance Test Driven Development with SpecFlow and Friends

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. Acceptance Test Driven Development with SpecFlow and Friends • Christopher Bartling • Joel Levandoski

  2. Contact information • Christopher Bartling • chris.bartling@gmail.com • Twitter: @cbartling • Joel Levandoski • joel.levandoski@gmail.com • Twitter: @joellevandoski

  3. Topics • Acceptance Test Driven Development (ATDD) • SpecFlow for .NET • Behavior Driven Development (BDD) tool • WatiN and WebAii • Live demonstration • Questions

  4. Acceptance Test Driven Development • ATDD • Acceptance tests are executable specifications of desired behavior and functionality of the system • Expressed in language of the problem domain • Automated • Regression suite • Development is driven from the outside-in

  5. ATDD vs. TDD • TDD is extremely valuable, but you need more • Achieve great unit test coverage and still not deliver valueto the customer • ATDD focuses on complete features and functionality • ATDD: macro view • TDD: micro view

  6. SpecFlow for .NET • BDD testing framework • Integrates nicely with Visual Studio • Acceptance tests manifest themselves as features and scenarios • SpecFlow generates automated test from features • SpecFlow tests run as normal xUnit tests • Visual Studio test runner, build server

  7. Features • Describe some piece of functionality of the system • Maintained in a .feature file • Plain readable text • Understandable by all parties, including business • Gherkin format, popularized by Cucumber • Features contain one or more scenarios

  8. Feature file example Feature: Calculate Net Present Value In order analyze the profitability of a project As a project manager I want to be able to calculate the project’s Net Present Value Scenario: A project is rejected Given a project to evaluate When data is entered reflecting a failing project ROI scenario Then the net present value calculator will reject the project

  9. Scenarios • A scenario describes a single acceptance test for a feature • Most features are composed of multiple scenarios • SpecFlow generates a test for each scenario • The name of the test is generated from the scenario title

  10. Scenario example Scenario: A project is rejected when its NPV is negative Given a project to evaluate When data is entered reflecting a failing ROI scenario Then the net present value calculator willreject the project

  11. Scenario steps • Used to compose a scenario • Custom code to automate your application • Describe preconditions, triggering action, and verification of outputs for the acceptance test • Given: preconditions • When: triggering action • Then: behavior and state verifications

  12. Scenario step example Givena project to evaluate is matched to the following step definition binding… [Given(@"a project to evaluate")] public void GivenAProjectToEvaluate() { . . . }

  13. Set up and tear down • Attributes for before and after events • TestRun • Feature • Scenario, ScenarioBlock • Step • Specificity achieved when used with tags

  14. Tags • Markers that can be applied to features and scenarios • Useful for selectively mixing in behavior • Used to categorize scenarios • Some unit test frameworks support this categorization tagging • Custom tags you define

  15. Tag example @WatiN Scenario: Save valid sample size mid range Giventhe user enters 10 as sample size Whenthe user selects save Thenthe value is stored

  16. Tag example used with BeforeScenario [BeforeScenario("WatiN”)] public void BeforeScenarioUsingWatiN() { ... }

  17. Background • Common preconditions for all scenarios in a feature • Contains one or more scenario steps • Executed before any other steps in the scenario • SpecFlow generates a method from the background element in the feature file in the test class • Invoked from each scenario test case in the test class

  18. Background example Background: Given that the welcome page is displayed Scenario: Add a comment to a book being reviewed . . .

  19. Scenario outlines • Data-driven scenarios or scenario templates • Consists of • Scenario template specification with data placeholders • Set of examples providing values for placeholders • SpecFlow generates parameterized test logic for the scenario outline and individual test method for each example set

  20. Scenario outline example Scenario Outline: Score calculation tables Given a new bowling game When I roll the following series: <rolls> Then my total score should be <total score> Examples: | game | rolls | total score | | beginners game | 2,7,3,4,1,1,5,1,1,1,1,1,1,1,1,1,1,1,5,1 | 40 | | one single spare | 2,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 | 29 |

  21. ScenarioContext • ScenarioContext.Current.Pending() • Causes the step definition to return pending • Used to signal a stubbed step definition • ScenarioContext.Currentdictionary • Allows you to carry context/state across step definitions participating in scenario

  22. WatiN • Open source browser automation tool for IE and Firefox • Similar to Selenium, WebDriver, Watir • Browser abstraction • Find elements using CSS selectors • Interact with AJAX web elements • Handle popup dialogs (native and HTML)

  23. WebAii • Browser automation tool from Telerik • Automates both web 2.0 and Silverlight applications • HTML element wrappers • WaitForElement(s) support when using AJAX • Identifying elements using LINQ • Invoke JavaScript directly from test code

  24. Best practices • Write high-level specifications • Specifications should remain stable over time • Build a scripting interface for manipulating your system under test (SUT) • Focus specifications on isolated behaviors • Think of specifications in Given-When-Then format • Use the Page Object pattern

  25. Smells • Specifications are constantly changing • Specifications are composed of “sequential command executions” • Specifications have a lot of instrumentation or fixture code • Specification examples exhibit same structure

  26. Net Present Value Calculator Demo • Used in capital budgeting • Measures the excess or shortfall of cash flows, in present value terms, once financing terms have been covered • Demo has two implementations • ASP.NET MVC • Silverlight

  27. Questions?

  28. Literature cited • http://www.concordion.org/Technique.html • http://www.telerik.com/automated-testing-tools/webaii-framework-features.aspx • http://watin.org/ • http://www.specflow.org/ • http://code.google.com/p/selenium/wiki/PageObjects

More Related