bdd with visual studio 2010, spec flow and watin

18
DotNetNuke Corp. Confidential © 2011 All rights reserved. BDD WITH VISUAL STUDIO 2010, SPECFLOW AND WATIN CHARLES NURSE SENIOR ARCHITECT, DOTNETNUKE CORP. [email protected] @CNURSE

Upload: charles-nurse

Post on 08-May-2015

2.178 views

Category:

Technology


3 download

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

Page 1: Bdd with Visual Studio 2010, Spec Flow and WatiN

DotNetNuke Corp. Confidential © 2011 All rights reserved.

BDD WITH VISUAL STUDIO 2010, SPECFLOW AND WATIN

CHARLES NURSESENIOR ARCHITECT, DOTNETNUKE [email protected] @CNURSE

Page 2: Bdd with Visual Studio 2010, Spec Flow and WatiN

2DotNetNuke Corp. Confidential © 2011 All rights reserved. 2DotNetNuke Corp. Confidential © 2011 All rights reserved.

AGENDA• Intro to BDD• Gherkins• SpecFlow• WatiN• Demos

Page 3: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 4: Bdd with Visual Studio 2010, Spec Flow and WatiN

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)

Page 5: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 6: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 7: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 8: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 9: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 10: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 11: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 12: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 13: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 14: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 15: Bdd with Visual Studio 2010, Spec Flow and WatiN

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!

Page 16: Bdd with Visual Studio 2010, Spec Flow and WatiN

16DotNetNuke Corp. Confidential © 2011 All rights reserved. 16DotNetNuke Corp. Confidential © 2011 All rights reserved.

PART 4 – WATIN• Finish the Tests

Page 17: Bdd with Visual Studio 2010, Spec Flow and WatiN

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

Page 18: Bdd with Visual Studio 2010, Spec Flow and WatiN

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