Presentation is loading. Please wait.

Presentation is loading. Please wait.

Acceptance Test Driven Development with SpecFlow and Friends

Similar presentations


Presentation on theme: "Acceptance Test Driven Development with SpecFlow and Friends"— Presentation transcript:

1 Acceptance Test Driven Development with SpecFlow and Friends
Christopher Bartling Joel Levandoski

2 Contact information Christopher Bartling Joel Levandoski

3 Administrative stuff Presentation and demo are available on BitBucket.org

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

5 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

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

7

8 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

9 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

10 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

11 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

12 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 will reject the project

13 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

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

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

16 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

17 Tag example @WatiN Scenario: Save valid sample size mid range Given the user enters 10 as sample size When the user selects save Then the value is stored

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

19 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

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

21 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

22 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 |

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

24 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)

25 WebAii Browser automation tool from Telerik HTML element wrappers
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

26 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

27 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

28 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

29 Questions?

30 Literature cited http://www.concordion.org/Technique.html
tools/webaii-framework-features.aspx bjects


Download ppt "Acceptance Test Driven Development with SpecFlow and Friends"

Similar presentations


Ads by Google