bdd with visual studio 2010, spec flow and watin
DESCRIPTION
This is my session on Practical BDD using Visual Studio, SpecFlow and WatiN from Prairie DevCon West in Calgary, Mar 13-15, 2012.TRANSCRIPT
DotNetNuke Corp. Confidential © 2011 All rights reserved.
BDD WITH VISUAL STUDIO 2010, SPECFLOW AND WATIN
CHARLES NURSESENIOR ARCHITECT, DOTNETNUKE [email protected] @CNURSE
2DotNetNuke Corp. Confidential © 2011 All rights reserved. 2DotNetNuke Corp. Confidential © 2011 All rights reserved.
AGENDA• Intro to BDD• Gherkins• SpecFlow• WatiN• Demos
3DotNetNuke Corp. Confidential © 2011 All rights reserved. 3DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART I – BEHAVIOR DRIVEN DEVELOPMENT• Developed by Dan North• Response to some issues with TDD
» Where to start» What to test and what not to test» How much to test in one go» What to call the tests» How to understand why a test fails
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
4DotNetNuke Corp. Confidential © 2011 All rights reserved. 4DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART I – BEHAVIOR DRIVEN DEVELOPMENT• Driven by Business Value• Realized through the Interface (GUI)• Tests are defined in a natural language (Gherkins)
5DotNetNuke Corp. Confidential © 2011 All rights reserved. 5DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART I – BEHAVIOR DRIVEN DEVELOPMENT• BDD Practices
» Establish the goals of different stakeholders» Drawing out features which will achieve those goals using
feature injection» Involve stakeholders through outside–in software development» Use examples to describe the behavior of the application» Automate those examples to provide feedback and regression
testing» Use 'should' when describing the behavior of software» Use 'ensure' when describing responsibilities of software» Use mocks to stand-in for modules of code which have not yet
been written
6DotNetNuke Corp. Confidential © 2011 All rights reserved. 6DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 2 – GHERKINS• Natural Language definition of tests.
» TDD – Arrange, Act, Assert
• Gherkin – Given, When, Then» Given – defines the conditions that must exits for the test to be run» When – defines the action a “user” will execute» Then – defines the expectations of the Test
• Gherkins Frameworks» Cucumber – Ruby» Lettuce – Python» Specflow - .NET
7DotNetNuke Corp. Confidential © 2011 All rights reserved. 7DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 2 – GHERKINS• Example – "Refunded or exchanged items should be returned to
stock.“
• Customer, Product Manager, Developer or QA engineer might clarify the requirements by breaking this down into specific scenarios
• Scenario 1: Refunded items should be returned to stock• Scenario 2: Replaced items should be returned to stock
8DotNetNuke Corp. Confidential © 2011 All rights reserved. 8DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 2 – GHERKINS• Scenario 1: Refunded items should be returned to stock
» Given a customer previously bought a black sweater from me» and I currently have three black sweaters left in stock
» When he returns the sweater for a refund
» Then I should have four black sweaters in stock
9DotNetNuke Corp. Confidential © 2011 All rights reserved. 9DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 2 – GHERKINS• Scenario 2: Replaced items should be returned to stock
» Given that a customer buys a blue garment» and I have two blue garments in stock» and three black garments in stock.
» When he returns the garment for a replacement in black,
» Then I should have three blue garments in stock» and two black garments in stock
10DotNetNuke Corp. Confidential © 2011 All rights reserved. 10DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 2 – GHERKINS• Programmer-domain examples
• Example 1: New lists are empty» Given a new list» Then the list should be empty
• Example 2: Lists with things in them are not empty» Given a new list» When we add an object » Then the list should not be empty
11DotNetNuke Corp. Confidential © 2011 All rights reserved. 11DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 3 – SPECFLOW• SpecFlow aims at bridging the communication gap between
domain experts and developers by binding business readable behavior specifications to the underlying implementation.
SpecFlow.org
• Visual Studio Extension – to support Gherkin language tests» www.specflow.org» https://github.com/techtalk/SpecFlow
• SpecFlow Demo
12DotNetNuke Corp. Confidential © 2011 All rights reserved. 12DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 3 – SPECFLOW• Demo Summary• Review of SpecFlow in VS 2010
» Reviewed the Extension Manager Addin» Reviewed the Nuget Package (SpecFlow/NUnit) integration)» Added a SpecFlow Feature» Run SpecFlow Scenarios» Added Steps File» Updated Feature» Updated Steps File
13DotNetNuke Corp. Confidential © 2011 All rights reserved. 13DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 4 – WATIN• Browser Automation Framework
» Web Application Testing in .NET» http://watin.org/
• Inspired by WatiR (Web Application Testing in Ruby)
• Supports IE (6+) or Firefox (2+)
• Licensed under Apache License 2.0
• Available as a Nuget package
14DotNetNuke Corp. Confidential © 2011 All rights reserved. 14DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 4 – WATIN• Automate all major HTML elements with ease
• Find elements by multiple attributes
• Native support for Page and Control model.
• Supports AJAX website testing
• Supports creating screenshots of webpages
• Supports frames (cross domain) and IFrames
15DotNetNuke Corp. Confidential © 2011 All rights reserved. 15DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 4 – WATIN• Handles popup dialogs like alert, confirm, login etc..
• Supports HTML dialogs (modal and modeless)
• Easy to integrate with your favorite (unit) test tool
• Can be used with any .Net Language
• Downloaded more than 120,000 times.
• Since its open source you can add/contribute new features yourself!
16DotNetNuke Corp. Confidential © 2011 All rights reserved. 16DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 4 – WATIN• Finish the Tests
17DotNetNuke Corp. Confidential © 2011 All rights reserved. 17DotNetNuke Corp. Confidential © 2011 All rights reserved.
PART 4 – WATIN• Demo Summary• Review of SpecFlow in VS 2010
» Reviewed the Nuget Package (WatiN) integration)» Completed the SpecFlow Scenario» Added a second SpecFlow Scenario» Reviewed a real Scenario in a real Application
18DotNetNuke Corp. Confidential © 2011 All rights reserved. 18DotNetNuke Corp. Confidential © 2011 All rights reserved.
THANK YOU• For more info:
» www.specflow.org» https://github.com/techtalk/SpecFlow» http://watin.org/» www.dotnetnuke.com
• Feedback» https://www.surveymonkey.com/s/GHLYGSS
• Email: [email protected]• Blog: www.charlesnurse.com • Twitter: @cnurse