Specification by example with specflow 110217
Upcoming SlideShare
Loading in...5
×
 

Specification by example with specflow 110217

on

  • 13,030 views

Read more about the presentation here: http://www.marcusoft.net/2011/02/specflow-presentation-at-sweden.html

Read more about the presentation here: http://www.marcusoft.net/2011/02/specflow-presentation-at-sweden.html

Statistics

Views

Total Views
13,030
Views on SlideShare
12,953
Embed Views
77

Actions

Likes
10
Downloads
306
Comments
0

7 Embeds 77

http://www.marcusoft.net 55
http://thinkery.me 9
http://www.slashdocs.com 8
http://www.linkedin.com 2
http://www.slideshare.net 1
http://static.slidesharecdn.com 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Specification by example with specflow 110217 Specification by example with specflow 110217 Document Transcript

  • Specification by example with SpecFlow Marcus Hammarberg Avega Group www.marcusoft.netsöndag den 20 februari 2011 (v.)
  • http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257söndag den 20 februari 2011 (v.)Executable specifications - that verifies that the system is behaving as expected.You want it - i can give it to you!This presentation is about Specification by example with SpecFlow.As a last teaser, a quote by Dan North.Hows that’s for something to live up to? :)
  • http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257 http://www.unit5.org/debordc/MPj04071740000[1].jpgsöndag den 20 februari 2011 (v.)Executable specifications - that verifies that the system is behaving as expected.You want it - i can give it to you!This presentation is about Specification by example with SpecFlow.As a last teaser, a quote by Dan North.Hows that’s for something to live up to? :)
  • “It’s not a silver bullet – but it seems a good start” Dan North http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257 http://www.unit5.org/debordc/MPj04071740000[1].jpgsöndag den 20 februari 2011 (v.)Executable specifications - that verifies that the system is behaving as expected.You want it - i can give it to you!This presentation is about Specification by example with SpecFlow.As a last teaser, a quote by Dan North.Hows that’s for something to live up to? :)
  • söndag den 20 februari 2011 (v.)My name is Marcus Hammarberg
  • söndag den 20 februari 2011 (v.)I work for Avega Group as an agile coach and consultant
  • söndag den 20 februari 2011 (v.)I have one wife
  • söndag den 20 februari 2011 (v.)two hobbies
  • söndag den 20 februari 2011 (v.)and three kids
  • söndag den 20 februari 2011 (v.)I have been working as a programmer
  • söndag den 20 februari 2011 (v.)since 1998 - mainly with Microsoft products
  • söndag den 20 februari 2011 (v.)During the last 6 years I have been more and more interested in how you can work effectivetogether
  • söndag den 20 februari 2011 (v.)with agile methods - such as scrum
  • Who are you?söndag den 20 februari 2011 (v.)
  • BDDsöndag den 20 februari 2011 (v.)What’s this BDD thing?Wasn’t it TDD? Or was it DDD? or xDD?Here’s a short background
  • TDDsöndag den 20 februari 2011 (v.)TDD (Test driven development) is a way to write code where you start from a test describingthe functionality you’re about to write. The test drives the production code from thedeveloper.There’s a lot of pros from that way of working- you think about the behaviour of the code before you write it- you can take small steps through complex problems- you only write the code that is really needed- the tests describes the functionality of the system- and, as a funny side-effect, you get tests for all the code you’re writing.But there’s some problems as well:- where to start- where to stop- you easily end up writing test that describes HOW the production code is implemented- TDD is lowlevel inside-out. You start at a single method or class. How did you get there?
  • Behaviour Driven Designsöndag den 20 februari 2011 (v.)All these problems can easily get to you when you start TDD’ing.This was addressed in a blogpost by Dan North (http://blog.dannorth.net/introducing-bdd/)in which he coined the term BDD - Behavior Driven Design.With BDD the behavior of the feature we’re about to implement is the focus.Also the language we’re using is very important in BDD. The whole idea is to use a languagethat everyone concerned can read and understand the langauge. So that we can talk aboutWHAT the feature does - separated from HOW.
  • Outside-in development http://www.adaptivepath.com/blog/wp-content/uploads/2009/02/oi_model_inward.jpgsöndag den 20 februari 2011 (v.)On of the problems of TDD, I took up, was that you didn’t know where to start. Or stop. Thathas to do with you working inside-out.BDD gives you the possibility to work from the outside-in.You start with failing acceptance test that runs end-to-end. When that is implemented - thisfeature is done!This is called ATDD by some - Acceptance test driven development
  • What’s all these DD’s?söndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s? • TDDsöndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s? • TDD • ATDDsöndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s? • TDD • ATDD • STDDsöndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s? • TDD • ATDD • STDD • BDDsöndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s? • TDD • ATDD • STDD • BDD • Specification by examplesöndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • What’s all these DD’s?söndag den 20 februari 2011 (v.)This is my humble understanding. Today- TDD - helps you write better code by writing a test before the production code- ATDD - start from a failing end-to-end acceptance test. Jenitta Andrea says this: ATDD is to describe a functional requirements of a story as concrete examples orexpectations before development is started- STDD - Story test driven development - don’t know much about this. Seems to be very likeATDDBDD - focus on the behavior of the feature. Liz Keogh : BDD’s focus is to discover the things we didn’t know, especially in the contexts that thescenarios or examples is run inSpecification by example - a way to specify something by giving concrete examples on howthey should work.
  • söndag den 20 februari 2011 (v.)Or you can use this great intro and skip the buzz-words altogether. From Gojko AdzicThis is a great sum up that I like by Janet Gregory:Where we choose to call it BDD or ATDD or Specification by Example, we want the same result– a shared common understanding of what is to be built to try to build the ‘thing’ right thefirst time.We know it never will be, but the less rework, the better.
  • Whether we choose to call it BDD or ATDD or Specification by Example, we want the same result – a shared common understanding of what is to be built to try to build the ‘thing’ right the first time. We know it never will be, but the less rework, the better. Janet Gregorysöndag den 20 februari 2011 (v.)Or you can use this great intro and skip the buzz-words altogether. From Gojko AdzicThis is a great sum up that I like by Janet Gregory:Where we choose to call it BDD or ATDD or Specification by Example, we want the same result– a shared common understanding of what is to be built to try to build the ‘thing’ right thefirst time.We know it never will be, but the less rework, the better.
  • Theorysöndag den 20 februari 2011 (v.)Some theory on the background of Specfication by example
  • User storiessöndag den 20 februari 2011 (v.)User stories is a Extreme Programming way to keep requirement small and manageable.It’s requirements in a sentence. Often using a template like this:In order to [benefit]As a [role]I want to [feature]That first part is seldom done in any use cases that i’ve read. And that’s the whole reason forthe function to exist.But this is, even though it’s short, still to wide and open for interpretations. Therefore userstories are often called “a placeholder for a further conversation”
  • User stories In order to [benefit] As a [role] I want to [feature]söndag den 20 februari 2011 (v.)User stories is a Extreme Programming way to keep requirement small and manageable.It’s requirements in a sentence. Often using a template like this:In order to [benefit]As a [role]I want to [feature]That first part is seldom done in any use cases that i’ve read. And that’s the whole reason forthe function to exist.But this is, even though it’s short, still to wide and open for interpretations. Therefore userstories are often called “a placeholder for a further conversation”
  • User storiessöndag den 20 februari 2011 (v.)User stories is a Extreme Programming way to keep requirement small and manageable.It’s requirements in a sentence. Often using a template like this:In order to [benefit]As a [role]I want to [feature]That first part is seldom done in any use cases that i’ve read. And that’s the whole reason forthe function to exist.But this is, even though it’s short, still to wide and open for interpretations. Therefore userstories are often called “a placeholder for a further conversation”
  • söndag den 20 februari 2011 (v.)And that discussion should lead to ...In order to better understand each other one powerful technique is to give concrete example.Just imaging how hard it would be to learn how to tie a Windsor-tie with just the theoreticaltext...It’s much easier with a couple of pictures to guide us
  • söndag den 20 februari 2011 (v.)So a good way to get this in a user story is to give a couple of examples on how it could beplayed out.They could be written with the template; Given / When / Then.
  • Given [initial context] When [event] Then [an outcome]söndag den 20 februari 2011 (v.)So a good way to get this in a user story is to give a couple of examples on how it could beplayed out.They could be written with the template; Given / When / Then.
  • Scenario 1: Account is in credit Given the account is in credit And the card is valid And the dispenser contains cash When the customer requests cash Then ensure the account is debited And ensure cash is dispensed And ensure the card is returnedsöndag den 20 februari 2011 (v.)So a good way to get this in a user story is to give a couple of examples on how it could beplayed out.They could be written with the template; Given / When / Then.
  • Scenario 2: Account is overdrawnpast the overdraft limitGiven the account is overdrawn And the card is validWhen the customer requests cashThen ensure a rejection message isdisplayed And ensure cash is not dispensed And ensure the card is returnedsöndag den 20 februari 2011 (v.)So a good way to get this in a user story is to give a couple of examples on how it could beplayed out.They could be written with the template; Given / When / Then.
  • söndag den 20 februari 2011 (v.)This looks a lot like a test-case, right?Or maybe a detailed requirements document?And wouldn’t that be nice to code after?There’s other pro’s too: - this foster the use of the same language for requirements, test and even maybe code - we can easily discuss the scenarios, add and remove stuff as we learn more. Before thesystem is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOWIf you now only didn’t have to run the test cases ...
  • Scenario 1: Account is in credit Given the account is in credit And the card is valid And the dispenser contains cash When the customer requests cash Then ensure the account is debited And ensure cash is dispensed And ensure the card is returnedsöndag den 20 februari 2011 (v.)This looks a lot like a test-case, right?Or maybe a detailed requirements document?And wouldn’t that be nice to code after?There’s other pro’s too: - this foster the use of the same language for requirements, test and even maybe code - we can easily discuss the scenarios, add and remove stuff as we learn more. Before thesystem is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOWIf you now only didn’t have to run the test cases ...
  • söndag den 20 februari 2011 (v.)This looks a lot like a test-case, right?Or maybe a detailed requirements document?And wouldn’t that be nice to code after?There’s other pro’s too: - this foster the use of the same language for requirements, test and even maybe code - we can easily discuss the scenarios, add and remove stuff as we learn more. Before thesystem is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOWIf you now only didn’t have to run the test cases ...
  • Wrap-up Executable specifications that verifies that the system behaves as expected, readable by all in the team, and around itsöndag den 20 februari 2011 (v.)This was the promise in the outset - is it kept?
  • It’s not in the tool http://www.barbellsandbacon.com/wp-content/uploads/2010/02/mlss_mario-hammer.jpgsöndag den 20 februari 2011 (v.)It’s very important to remember that the main benefit is not in the tool (which we will talkabout from now on).The benefit is that you get together and write down your common, shared knowledge in awell known format. In one place.That’s why anyone would dare call this a Silver Bullet
  • Toolssöndag den 20 februari 2011 (v.)When we have these scenarios in place it would be wonderful if we could use some kind oftool to verify that the system actually behaves as specified.And of course you could - this presentation would not be very meaningful otherwise.This was the idea of Cucumber that first was created in the Ruby-community. Cucumber canactually execute scenarios written in the Given/When/Then-syntax. This syntax is calledGherkin.For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the bestone is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • Tools http://buyorganicvegetable.com/images/Cucumber.jpgsöndag den 20 februari 2011 (v.)When we have these scenarios in place it would be wonderful if we could use some kind oftool to verify that the system actually behaves as specified.And of course you could - this presentation would not be very meaningful otherwise.This was the idea of Cucumber that first was created in the Ruby-community. Cucumber canactually execute scenarios written in the Given/When/Then-syntax. This syntax is calledGherkin.For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the bestone is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • Tools http://buyorganicvegetable.com/images/Cucumber.jpgsöndag den 20 februari 2011 (v.)When we have these scenarios in place it would be wonderful if we could use some kind oftool to verify that the system actually behaves as specified.And of course you could - this presentation would not be very meaningful otherwise.This was the idea of Cucumber that first was created in the Ruby-community. Cucumber canactually execute scenarios written in the Given/When/Then-syntax. This syntax is calledGherkin.For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the bestone is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • How does this work?söndag den 20 februari 2011 (v.)But how can text be executable - it’s so open, you can write almost anything?It’s pretty simple really:- SpecFlow creates an automated test for each scenario, with the test runner of your choice- Each row in the scenario (called a step) will then call a method, that you supply, called stepdefinition. The method defines what the step means; How do you define “Given I am on theActivity list”It might be easier with an example (nudge, nudge :)):- For the scenario above - SpecFlow will create a test called NavigateToCreateNewActivity- in that test SpecFlow will look and call methods with attributes as the steps, shown in theexample
  • How does this work? [Given("I am on the Activity list")] public void ThisNameIsNotImportant() [When("I click the Create New link")] public void SpecFlowSimplyUsesTheAttribute() [Then("I should be on the Create Activity page")] public void AndCouldntCareLessOfYourMethodName()söndag den 20 februari 2011 (v.)But how can text be executable - it’s so open, you can write almost anything?It’s pretty simple really:- SpecFlow creates an automated test for each scenario, with the test runner of your choice- Each row in the scenario (called a step) will then call a method, that you supply, called stepdefinition. The method defines what the step means; How do you define “Given I am on theActivity list”It might be easier with an example (nudge, nudge :)):- For the scenario above - SpecFlow will create a test called NavigateToCreateNewActivity- in that test SpecFlow will look and call methods with attributes as the steps, shown in theexample
  • No really, how does it WORK? http://www.specflow.org/getfile/a67f8885-4900-4803-a972-5f3c57364097/artifacts.aspxsöndag den 20 februari 2011 (v.)Here’s the technical part:1 - You write your scenarios in a .feature-file. Every time it’s saved SpecFlow will generate atest-class, that contains a test for each scenario2 - The generated code (that you never care about that code, or rather don’t touch it) it’s justthere to glue together your scenario with your step definitions.3 - When the tests are run by the test runner (just as ordinary unit tests), it will call you stepdefinitions in the order they are written in the scenario4 - And your step definitions then call your application or domain.
  • Step definitions http://www.treehugger.com/green%20footsteps%20generic.jpgsöndag den 20 februari 2011 (v.)So the trick lies in the step definitions.They are realizing the “promise” of the steps in the scenario.So when we write a step definition for “When I click the Create New Link” we need to find thatlink on the web page (I guess) and then click it.
  • Step definitions http://www.treehugger.com/green%20footsteps%20generic.jpgsöndag den 20 februari 2011 (v.)So the trick lies in the step definitions.They are realizing the “promise” of the steps in the scenario.So when we write a step definition for “When I click the Create New Link” we need to find thatlink on the web page (I guess) and then click it.
  • Step definitions Scenario: Navigate to Create new Activity Given I am on the Activity list When I click the Create New link Then I should be on the Create Activity page http://www.treehugger.com/green%20footsteps%20generic.jpgsöndag den 20 februari 2011 (v.)So the trick lies in the step definitions.They are realizing the “promise” of the steps in the scenario.So when we write a step definition for “When I click the Create New Link” we need to find thatlink on the web page (I guess) and then click it.
  • Automation http://www.cultofmac.com/wordpress/wp-content/uploads/2010/09/automator-icon.pngsöndag den 20 februari 2011 (v.)That’s called automation. To write a program that automate the running of another program.There’s a lot of framework that assists in this. But that’s not the purpose of this presentation.I would recommend Watin (http://watin.sourceforge.net/) for web applications and White(http://white.codeplex.com/) for Windows based applications.
  • Gherkinsöndag den 20 februari 2011 (v.)For a Swede Cucumber and Gherkins are more or less the same...But apparently that’s not true - these are Gherkins.And Gherkin is also the name of the language that scenarios are written in, invented by AlsakHellesoy.We will now examine it a bit closer.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • söndag den 20 februari 2011 (v.)The language is not big. This is the whole language.And that means it can be translated. To Swedish. Arabic. Bulgarian.And some more ... dubious languages too.but it gives us possibilities to write our scenarios in a suitable language.
  • Feature http://www.lushtshirts.co.uk/images/products/bug-feature.jpgsöndag den 20 februari 2011 (v.)Features and scenarios are written in .feature. It contains an feature description and one ormore scenarios.It’s a plain text file and it checked in with and versioned together with the code of the project.The feature is the description of the functionality. It’s plain text and doesn’t affect how thescenario is executed or interpreted. It’s very important though - in order to understand thescenarios.Every feature has a title and is written after the keyword Feature:
  • Feature http://www.lushtshirts.co.uk/images/products/bug-feature.jpgsöndag den 20 februari 2011 (v.)Features and scenarios are written in .feature. It contains an feature description and one ormore scenarios.It’s a plain text file and it checked in with and versioned together with the code of the project.The feature is the description of the functionality. It’s plain text and doesn’t affect how thescenario is executed or interpreted. It’s very important though - in order to understand thescenarios.Every feature has a title and is written after the keyword Feature:
  • Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpgsöndag den 20 februari 2011 (v.)A scenario also has a title and one or more stepsYou can use the Friends-rule to set a good name of the scenario. You know, the episodes ofFriends was called “The one where Ross and Rachel became a couple”, about half of theepisodes was called that if I remember correctly :)
  • Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpgsöndag den 20 februari 2011 (v.)A scenario also has a title and one or more stepsYou can use the Friends-rule to set a good name of the scenario. You know, the episodes ofFriends was called “The one where Ross and Rachel became a couple”, about half of theepisodes was called that if I remember correctly :)
  • Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpgsöndag den 20 februari 2011 (v.)A scenario also has a title and one or more stepsYou can use the Friends-rule to set a good name of the scenario. You know, the episodes ofFriends was called “The one where Ross and Rachel became a couple”, about half of theepisodes was called that if I remember correctly :)
  • GIVEN WHEN THENsöndag den 20 februari 2011 (v.)The scenarios follows the template Given / When / Then with the following meaning:- Given - in this step you setup the system in the desired state.- When - this is the actual action the scenario is about- Then - asserts that the right things happendThe scenario is executed top down. And the Given / When / Then keyword can be repeatedseveral times in the scenario, if you like. Not recommended but possible.And speaking of not recommended - you can write the Given / When / Thens in any orderyou want. But then you lose any pros of the structure in the first place.
  • Scenario: Simple GWT Given the intial state of the application is Running When I ask what the application state is Then I should see Running as the answersöndag den 20 februari 2011 (v.)The scenarios follows the template Given / When / Then with the following meaning:- Given - in this step you setup the system in the desired state.- When - this is the actual action the scenario is about- Then - asserts that the right things happendThe scenario is executed top down. And the Given / When / Then keyword can be repeatedseveral times in the scenario, if you like. Not recommended but possible.And speaking of not recommended - you can write the Given / When / Thens in any orderyou want. But then you lose any pros of the structure in the first place.
  • söndag den 20 februari 2011 (v.)The scenarios follows the template Given / When / Then with the following meaning:- Given - in this step you setup the system in the desired state.- When - this is the actual action the scenario is about- Then - asserts that the right things happendThe scenario is executed top down. And the Given / When / Then keyword can be repeatedseveral times in the scenario, if you like. Not recommended but possible.And speaking of not recommended - you can write the Given / When / Thens in any orderyou want. But then you lose any pros of the structure in the first place.
  • But? And?söndag den 20 februari 2011 (v.)There’s two more keywords AND and BUT to connect several steps with each other.AND and BUT refers back to the word above it. They are used to get a better flow in thelanguage.Try not do use AND/BUT in the When-step. Let that be a single action.
  • Expressionssöndag den 20 februari 2011 (v.)Sometime the steps are very similar to other existing steps.And it would be horrible if we needed to write every step definition explicit.Therefore Regular expressions can be used to have some part of the steps as variables.That will be converted into parameters to our step definition methods. Please note that theorder of the regular expressions are important.If you, like me, don’t like RegExps you’ll be happy to known that these two will get you veryfar.Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • Expressions When I write My test string in the textbox Test textboxsöndag den 20 februari 2011 (v.)Sometime the steps are very similar to other existing steps.And it would be horrible if we needed to write every step definition explicit.Therefore Regular expressions can be used to have some part of the steps as variables.That will be converted into parameters to our step definition methods. Please note that theorder of the regular expressions are important.If you, like me, don’t like RegExps you’ll be happy to known that these two will get you veryfar.Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • Expressions When I write My test string in the textbox Test textbox[When(@"I write (.*) in the textbox (.*)")]public void WriteInTextBox(string textToWrite,string wellKnownName)söndag den 20 februari 2011 (v.)Sometime the steps are very similar to other existing steps.And it would be horrible if we needed to write every step definition explicit.Therefore Regular expressions can be used to have some part of the steps as variables.That will be converted into parameters to our step definition methods. Please note that theorder of the regular expressions are important.If you, like me, don’t like RegExps you’ll be happy to known that these two will get you veryfar.Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • Expressions When I write My test string in the textbox Test textbox[When(@"I write (.*) in the textbox (.*)")]public void WriteInTextBox(string textToWrite,string wellKnownName) (.*) - en sträng => string (d+) - ett heltal => integersöndag den 20 februari 2011 (v.)Sometime the steps are very similar to other existing steps.And it would be horrible if we needed to write every step definition explicit.Therefore Regular expressions can be used to have some part of the steps as variables.That will be converted into parameters to our step definition methods. Please note that theorder of the regular expressions are important.If you, like me, don’t like RegExps you’ll be happy to known that these two will get you veryfar.Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • Expressions When I write My test string in the textbox Test textbox[When(@"I write (.*) in the textbox (.*)")]public void WriteInTextBox(string textToWrite,string wellKnownName) (.*) - en sträng => string (d+) - ett heltal => integersöndag den 20 februari 2011 (v.)Sometime the steps are very similar to other existing steps.And it would be horrible if we needed to write every step definition explicit.Therefore Regular expressions can be used to have some part of the steps as variables.That will be converted into parameters to our step definition methods. Please note that theorder of the regular expressions are important.If you, like me, don’t like RegExps you’ll be happy to known that these two will get you veryfar.Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • Backgroundsöndag den 20 februari 2011 (v.)With the keyword background you can run some steps before each scenario in the feature.It’s just like a ordinary scenario, it’s just run before the scenarios.<CLICK>In this example we set up the system under test in a common state for all the scenarios
  • Hookssöndag den 20 februari 2011 (v.)From Cucumber SpecFlow borrows the concept of hooks.Hooks are events that is fired in the following order.And you can “hook in” code here to do useful things: - Restore a database - Dump a log on error - Init variables before steps - etc
  • Hookssöndag den 20 februari 2011 (v.)From Cucumber SpecFlow borrows the concept of hooks.Hooks are events that is fired in the following order.And you can “hook in” code here to do useful things: - Restore a database - Dump a log on error - Init variables before steps - etc
  • Tagssöndag den 20 februari 2011 (v.)Hooks are cool but they become really powerful combined with Tags.Tags are simple small markers that can be written in your feature.Only one tag is supported by SpecFlow out of the box; @ignore that simply ignores thescenario. Great for stuff that isn’t ready yet.A tag becomes a test category and can be used to categorize your tests (acceptance test,dailes, slow running etc)But you can use tag to overload the hooks. So that a certain hook only is run when thescenario or feature has a certain tag.
  • Tagssöndag den 20 februari 2011 (v.)Hooks are cool but they become really powerful combined with Tags.Tags are simple small markers that can be written in your feature.Only one tag is supported by SpecFlow out of the box; @ignore that simply ignores thescenario. Great for stuff that isn’t ready yet.A tag becomes a test category and can be used to categorize your tests (acceptance test,dailes, slow running etc)But you can use tag to overload the hooks. So that a certain hook only is run when thescenario or feature has a certain tag.
  • @ignoresöndag den 20 februari 2011 (v.)Hooks are cool but they become really powerful combined with Tags.Tags are simple small markers that can be written in your feature.Only one tag is supported by SpecFlow out of the box; @ignore that simply ignores thescenario. Great for stuff that isn’t ready yet.A tag becomes a test category and can be used to categorize your tests (acceptance test,dailes, slow running etc)But you can use tag to overload the hooks. So that a certain hook only is run when thescenario or feature has a certain tag.
  • söndag den 20 februari 2011 (v.)Hooks are cool but they become really powerful combined with Tags.Tags are simple small markers that can be written in your feature.Only one tag is supported by SpecFlow out of the box; @ignore that simply ignores thescenario. Great for stuff that isn’t ready yet.A tag becomes a test category and can be used to categorize your tests (acceptance test,dailes, slow running etc)But you can use tag to overload the hooks. So that a certain hook only is run when thescenario or feature has a certain tag.
  • söndag den 20 februari 2011 (v.)You can use table to manage multiple data. The data will be passed to you step definition as aSpecFlow Table that has values for columns and rows. From that table you can read a data.
  • söndag den 20 februari 2011 (v.)You can use table to manage multiple data. The data will be passed to you step definition as aSpecFlow Table that has values for columns and rows. From that table you can read a data.
  • [Given("I have the following persons")] public void IHaveTheFollowingPersons (Table personsTable)söndag den 20 februari 2011 (v.)You can use table to manage multiple data. The data will be passed to you step definition as aSpecFlow Table that has values for columns and rows. From that table you can read a data.
  • SpecFlow.Assistsöndag den 20 februari 2011 (v.)Working with tables can be quite messy. But in this namespace (SpecFlow.Assist) there’ssome helpers to help us get around that.Check these examples out: - https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/Specs/05TablesAndAssist - https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/Specs/06CompareToAssist
  • Scenario outlinesöndag den 20 februari 2011 (v.)By using a scenario outline you could reuse the same scenario with several different data.In this way you can easily write several variants (permutations) of test data for the samescenario.This example will create 5 test that performs the calculation. How this is done depends on thetestrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTestcreates several tests.
  • Scenario outlinesöndag den 20 februari 2011 (v.)By using a scenario outline you could reuse the same scenario with several different data.In this way you can easily write several variants (permutations) of test data for the samescenario.This example will create 5 test that performs the calculation. How this is done depends on thetestrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTestcreates several tests.
  • Langaugesöndag den 20 februari 2011 (v.)You can change the language in your feature by using the #language : sv (for Swedish).But probably you want to do that for all your features, in the .config-file of the specificationproject.
  • ScenarioContext.Currentsöndag den 20 februari 2011 (v.)ScenarioContext is a small dictionary that is used to send data between your steps. It’s muchbetter than to use private variables in your step classes since that hinders step reuse etc.So better is to group your step definitions per logical unit; controller, page, functionSee https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/Specs/031ScenarioContext
  • AvegaCoach Activity Logsöndag den 20 februari 2011 (v.)I have developed a small example site that shows how these techniques can be used.It’s a small site to keep track of the activities that persons in my group, AvegaCoach,undertake.This is the domain model and I’ve scaffolded the whole site.I have written two sets of specifications- against the controller level (https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/SpecsAgainstController)- against the web pages (https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/SpecsAgainstGUI)to show how they differ.
  • On with the code! http://burningbird.net/photos/thumb-victwait.jpgsöndag den 20 februari 2011 (v.)On to the code!
  • Learn moresöndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/söndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/söndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlowsöndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow • http://github.com/techtalk/SpecFlow-Examplessöndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow • http://github.com/techtalk/SpecFlow-Examples • http://github.com/aslakhellesoy/cucumber/wikisöndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow • http://github.com/techtalk/SpecFlow-Examples • http://github.com/aslakhellesoy/cucumber/wiki • http://www.marcusoft.net/search/label/SpecFlowsöndag den 20 februari 2011 (v.)
  • Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow • http://github.com/techtalk/SpecFlow-Examples • http://github.com/aslakhellesoy/cucumber/wiki • http://www.marcusoft.net/search/label/SpecFlow • https://github.com/marcushammarberg/ ProgressiveNetDemossöndag den 20 februari 2011 (v.)
  • And even moresöndag den 20 februari 2011 (v.)
  • And even moresöndag den 20 februari 2011 (v.)
  • And even moresöndag den 20 februari 2011 (v.)
  • And even moresöndag den 20 februari 2011 (v.)
  • And even moresöndag den 20 februari 2011 (v.)
  • www.marcusoft.net marcus.hammarberg@avegagroup.sesöndag den 20 februari 2011 (v.)Thanks for listening
  • www.marcusoft.net marcus.hammarberg@avegagroup.sesöndag den 20 februari 2011 (v.)Thanks for listening
  • söndag den 20 februari 2011 (v.)The end