220 likes | 624 Vues
Required Slide. SESSION CODE: DPR302. Behavior Driven Development in the Real World. David Starr Pluralsight Instructor ALM Consultant Visual Studio ALM MVP. starr@pluralsight.com Blog: ElegantCode.com @ elegantcoder. In This Session. Conversations About Software
E N D
Required Slide SESSION CODE: DPR302 Behavior Driven Development in the Real World David Starr Pluralsight Instructor ALM Consultant Visual Studio ALM MVP starr@pluralsight.com Blog: ElegantCode.com @elegantcoder
In This Session • Conversations About Software • Expressing Desirements Well • Making Requirements from Desirements • Specification in Context • BDD Tools
Communication is Still a Big Problem • So we use specifications • Use Cases • UML diagrams and models • Numerous large document models • Specification and Requirements • Can be expensive to produce • Good enough often preferred to perfect • Must evolve easily as the software does This isn’t what I thought we agreed on.
Draw It First • Users think at this level • Software has behavior at this level • UI elements give us something to discuss Paper Whiteboards Visio PowerPoint SketchFlow
Expressing Desirements • User Stories represent needed conversations As a <application role> I want <some feature or behavior> So that <I get some benefit> • Scenarios document the conversation took place Given <some initial context> When <this happens> Then <this should be the result> Desirements are things we wish the software did. But it doesn’t. Yet.
A Complete User Story Story: Remove Item From Shopping Cart As aCustomer with Products in my Cart I wantto remove an ItemSo I canchange my mind about buying it Scenario: Multiple Items in CartGiven a Cart with multiple Items in itWhen 1 Item is removedThen the other Items are still in the Cart And the Cart Item Count is correct And the Cart Subtotal reflects the remaining Items
Scenarios Work at Many Levels Customer Domain Concepts UI Element Behavior Input Validation Services Class Behavior Repositories Developer
Making Requirements from Desirements • Executable Specifications Expressing requirements such that they are also tests Because Microsoft Word documents can’t prove software works • Sweet Aromas of Executable Specifications • Meaningful to all interested parties • Unambiguously demonstrate if the requirement is met • Drive out a testable design • Simple
Using Executable Specifications As a I want So that As a I want So that • Make tests that read as Desirements • Tests fail against the SUT • Tests pass against the SUT • Discuss results with customer • Add more and refine as conversations occur Given When Then Given When Then Given When Then Given When Then Given When Then Given When Then
1, 2, 3 [TestMethod] public void Total_Should_Be_1_When_1_Product_Added() { var cart = new ShoppingCart("TEST"); cart.AddItem(new Product("SKU")); Assert.AreEqual(1, cart.TotalItems); }
Variations on a Theme User Story Structure AAA Context Specification
Sharing Context • Keeps our tests DRY • Reuse existing classes
Context Chaining • Keeps our tests DRY • Can be fragile • Watch Depth of Inheritance
MSpec • Popular Context / Specification library • Love it or hate it • Less to type than rolling your own • May replace existing your existing unit test framework • Includes report generator • Get it here: http://link.pluralsight.com/39um = () =>
StoryQ • Get started with BDD quickly • Too prescriptive for some • Fluent interface for ease-of-use • Compatible with MSTest / NUnit / XUnit • Get it here: http://link.pluralsight.com/3jaf
Other Projects of Interest • StorEvil – Another good .NET BDD libraryhttp://link.pluralsight.com/4n4z • SpecFlow – Another good .NET BDD libraryhttp://link.pluralsight.com/3uwd • Cucumber – BDD for Ruby and IronRubyhttp://link.pluralsight.com/56j7 • Gherkin – A DSL for BDDhttp://link.pluralsight.com/46nm • StoryTeller- .NET native alternative to Fitnessehttp://link.pluralsight.com/5vdn
Summary • Better understand each other before getting started • Ideas of Functionality are Desirements • Desirements express well as User Stories • BDD helps turn Desirements into Requirements • There are many supporting tools to help starr@pluralsight.com Blog: ElegantCode.com @elegantcoder
Required Slide Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Required Slide Complete an evaluation on CommNet and enter to win!
Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st http://northamerica.msteched.com/registration You can also register at the North America 2011 kiosk located at registrationJoin us in Atlanta next year
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.