SlideShare ist ein Scribd-Unternehmen logo
1 von 107
Downloaden Sie, um offline zu lesen
Specification by example
                    with SpecFlow

                                   Marcus Hammarberg
                                      Avega Group
                                   www.marcusoft.net
söndag den 20 februari 2011 (v.)
http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257




sö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].jpg




sö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].jpg




sö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 effective
together
söndag den 20 februari 2011 (v.)

with agile methods - such as scrum
Who are you?


söndag den 20 februari 2011 (v.)
BDD

sö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
TDD




söndag den 20 februari 2011 (v.)

TDD (Test driven development) is a way to write code where you start from a test describing
the functionality you’re about to write. The test drives the production code from the
developer.

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
                                                     Design


sö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 language
that everyone concerned can read and understand the langauge. So that we can talk about
WHAT the feature does - separated from HOW.
Outside-in
                                   development




                                                      http://www.adaptivepath.com/blog/wp-content/uploads/2009/02/oi_model_inward.jpg

sö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. That
has 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 - this
feature 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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
What’s all these DD’s?

                     • TDD




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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
What’s all these DD’s?

                     • TDD
                     • ATDD




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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
What’s all these DD’s?

                     • TDD
                     • ATDD
                     • STDD



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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
What’s all these DD’s?

                     • TDD
                     • ATDD
                     • STDD
                     • BDD


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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
What’s all these DD’s?

                     • TDD
                     • ATDD
                     • STDD
                     • BDD
                     • Specification by example

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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they 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 or
expectations before development is started

- STDD - Story test driven development - don’t know much about this. Seems to be very like
ATDD

BDD - 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 the
scenarios or examples is run in

Specification by example - a way to specify something by giving concrete examples on how
they should work.
söndag den 20 februari 2011 (v.)

Or you can use this great intro and skip the buzz-words altogether. From Gojko Adzic

This 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 the
first 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 Gregory




söndag den 20 februari 2011 (v.)

Or you can use this great intro and skip the buzz-words altogether. From Gojko Adzic

This 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 the
first time.

We know it never will be, but the less rework, the better.
Theory



söndag den 20 februari 2011 (v.)

Some theory on the background of Specfication by example
User stories




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 for
the function to exist.

But this is, even though it’s short, still to wide and open for interpretations. Therefore user
stories 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 for
the function to exist.

But this is, even though it’s short, still to wide and open for interpretations. Therefore user
stories are often called “a placeholder for a further conversation”
User stories




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 for
the function to exist.

But this is, even though it’s short, still to wide and open for interpretations. Therefore user
stories 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 theoretical
text...

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 be
played 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 be
played 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 returned


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 be
played out.

They could be written with the template; Given / When / Then.
Scenario 2: Account is overdrawn
past the overdraft limit
Given the account is overdrawn
 And the card is valid
When the customer requests cash
Then ensure a rejection message is
displayed
  And ensure cash is not dispensed
  And ensure the card is returned
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 be
played 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 the
system is implemented

   - it’s easy to see which functionality that is included (in a release for example)

   - and finally it’s VAD separated from HOW

If 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 returned


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 the
system is implemented

   - it’s easy to see which functionality that is included (in a release for example)

   - and finally it’s VAD separated from HOW

If 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 the
system is implemented

   - it’s easy to see which functionality that is included (in a release for example)

   - and finally it’s VAD separated from HOW

If 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
    it



sö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.jpg




söndag den 20 februari 2011 (v.)

It’s very important to remember that the main benefit is not in the tool (which we will talk
about from now on).

The benefit is that you get together and write down your common, shared knowledge in a
well known format. In one place.

That’s why anyone would dare call this a Silver Bullet
Tools




söndag den 20 februari 2011 (v.)

When we have these scenarios in place it would be wonderful if we could use some kind of
tool 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 can
actually execute scenarios written in the Given/When/Then-syntax. This syntax is called
Gherkin.

For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best
one is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
Tools




                  http://buyorganicvegetable.com/images/Cucumber.jpg




söndag den 20 februari 2011 (v.)

When we have these scenarios in place it would be wonderful if we could use some kind of
tool 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 can
actually execute scenarios written in the Given/When/Then-syntax. This syntax is called
Gherkin.

For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best
one is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
Tools




                  http://buyorganicvegetable.com/images/Cucumber.jpg




söndag den 20 februari 2011 (v.)

When we have these scenarios in place it would be wonderful if we could use some kind of
tool 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 can
actually execute scenarios written in the Given/When/Then-syntax. This syntax is called
Gherkin.

For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best
one 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 step
definition. The method defines what the step means; How do you define “Given I am on the
Activity 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 the
example
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 step
definition. The method defines what the step means; How do you define “Given I am on the
Activity 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 the
example
No really,
                           how does it WORK?




                                   http://www.specflow.org/getfile/a67f8885-4900-4803-a972-5f3c57364097/artifacts.aspx



sö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 a
test-class, that contains a test for each scenario

2 - The generated code (that you never care about that code, or rather don’t touch it) it’s just
there 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 step
definitions in the order they are written in the scenario

4 - And your step definitions then call your application or domain.
Step definitions




                                    http://www.treehugger.com/green%20footsteps%20generic.jpg


sö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 that
link on the web page (I guess) and then click it.
Step definitions




                                    http://www.treehugger.com/green%20footsteps%20generic.jpg


sö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 that
link 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.jpg


sö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 that
link on the web page (I guess) and then click it.
Automation




                                                 http://www.cultofmac.com/wordpress/wp-content/uploads/2010/09/automator-icon.png



sö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.
Gherkin




sö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 Alsak
Hellesoy.

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.jpg


söndag den 20 februari 2011 (v.)

Features and scenarios are written in .feature. It contains an feature description and one or
more 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 the
scenario is executed or interpreted. It’s very important though - in order to understand the
scenarios.

Every feature has a title and is written after the keyword Feature:
Feature




                                                             http://www.lushtshirts.co.uk/images/products/bug-feature.jpg


söndag den 20 februari 2011 (v.)

Features and scenarios are written in .feature. It contains an feature description and one or
more 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 the
scenario is executed or interpreted. It’s very important though - in order to understand the
scenarios.

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.jpg

söndag den 20 februari 2011 (v.)

A scenario also has a title and one or more steps

You can use the Friends-rule to set a good name of the scenario. You know, the episodes of
Friends was called “The one where Ross and Rachel became a couple”, about half of the
episodes was called that if I remember correctly :)
Scenario




                                         http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpg

söndag den 20 februari 2011 (v.)

A scenario also has a title and one or more steps

You can use the Friends-rule to set a good name of the scenario. You know, the episodes of
Friends was called “The one where Ross and Rachel became a couple”, about half of the
episodes was called that if I remember correctly :)
Scenario




                                         http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpg

söndag den 20 februari 2011 (v.)

A scenario also has a title and one or more steps

You can use the Friends-rule to set a good name of the scenario. You know, the episodes of
Friends was called “The one where Ross and Rachel became a couple”, about half of the
episodes was called that if I remember correctly :)
GIVEN
                                   WHEN
                                   THEN
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 happend

The scenario is executed top down. And the Given / When / Then keyword can be repeated
several 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 order
you 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 answer




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 happend

The scenario is executed top down. And the Given / When / Then keyword can be repeated
several 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 order
you 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 happend

The scenario is executed top down. And the Given / When / Then keyword can be repeated
several 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 order
you 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 the
language.

Try not do use AND/BUT in the When-step. Let that be a single action.
Expressions




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 the
order 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 very
far.

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'




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 the
order 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 very
far.

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 the
order 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 very
far.

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 => integer

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 the
order 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 very
far.

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 => integer

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 the
order 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 very
far.

Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
Background




sö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
Hooks




sö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
Hooks




sö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
Tags


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 the
scenario. 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 the
scenario or feature has a certain tag.
Tags


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 the
scenario. 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 the
scenario or feature has a certain tag.
@ignore



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 the
scenario. 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 the
scenario 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 the
scenario. 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 the
scenario 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 a
SpecFlow 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 a
SpecFlow 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 a
SpecFlow Table that has values for columns and rows. From that table you can read a data.
SpecFlow.Assist


söndag den 20 februari 2011 (v.)

Working with tables can be quite messy. But in this namespace (SpecFlow.Assist) there’s
some 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 outline




sö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 same
scenario.

This example will create 5 test that performs the calculation. How this is done depends on the
testrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTest
creates several tests.
Scenario outline




sö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 same
scenario.

This example will create 5 test that performs the calculation. How this is done depends on the
testrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTest
creates several tests.
Langauge




sö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 specification
project.
ScenarioContext.Current




söndag den 20 februari 2011 (v.)

ScenarioContext is a small dictionary that is used to send data between your steps. It’s much
better 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, function

See https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/Specs/
031ScenarioContext
AvegaCoach Activity Log




sö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.jpg




söndag den 20 februari 2011 (v.)

On to the code!
Learn more




sö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/SpecFlow




sö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




sö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




sö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




sö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/
                              ProgressiveNetDemos


söndag den 20 februari 2011 (v.)
And even more




söndag den 20 februari 2011 (v.)
And even more




söndag den 20 februari 2011 (v.)
And even more




söndag den 20 februari 2011 (v.)
And even more




söndag den 20 februari 2011 (v.)
And even more




söndag den 20 februari 2011 (v.)
www.marcusoft.net
                                   marcus.hammarberg@avegagroup.se
söndag den 20 februari 2011 (v.)

Thanks for listening
www.marcusoft.net
                                   marcus.hammarberg@avegagroup.se
söndag den 20 februari 2011 (v.)

Thanks for listening
söndag den 20 februari 2011 (v.)

The end

Weitere ähnliche Inhalte

Mehr von Marcus Hammarberg

20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile BoardMarcus Hammarberg
 
How kanban Saved a hospital in Indonesia
How kanban Saved a hospital in IndonesiaHow kanban Saved a hospital in Indonesia
How kanban Saved a hospital in IndonesiaMarcus Hammarberg
 
How kanban Saved a hospital in Indoneisa OreDev 2016
How kanban Saved a hospital in Indoneisa OreDev 2016How kanban Saved a hospital in Indoneisa OreDev 2016
How kanban Saved a hospital in Indoneisa OreDev 2016Marcus Hammarberg
 
How kanban saved a hospital in Indoneisa LKNA2016
How kanban saved a hospital in Indoneisa LKNA2016How kanban saved a hospital in Indoneisa LKNA2016
How kanban saved a hospital in Indoneisa LKNA2016Marcus Hammarberg
 
ca 10 minutes on effective meetings
ca 10 minutes on effective meetingsca 10 minutes on effective meetings
ca 10 minutes on effective meetingsMarcus Hammarberg
 
10 minutes on root cause analysis
10 minutes on root cause analysis10 minutes on root cause analysis
10 minutes on root cause analysisMarcus Hammarberg
 
15 minutes on impact mapping
15 minutes on impact mapping15 minutes on impact mapping
15 minutes on impact mappingMarcus Hammarberg
 
20 minutes on strategic plans
20 minutes on strategic plans20 minutes on strategic plans
20 minutes on strategic plansMarcus Hammarberg
 
Impact mapping @ YOW West 2015
Impact mapping  @ YOW West 2015Impact mapping  @ YOW West 2015
Impact mapping @ YOW West 2015Marcus Hammarberg
 
Kanban in Action - YOW West 2015
Kanban in Action - YOW West 2015Kanban in Action - YOW West 2015
Kanban in Action - YOW West 2015Marcus Hammarberg
 
Pass the pennies - Lean game simulation
Pass the pennies - Lean game simulationPass the pennies - Lean game simulation
Pass the pennies - Lean game simulationMarcus Hammarberg
 
Numbers simulation - less is more!
Numbers simulation - less is more!Numbers simulation - less is more!
Numbers simulation - less is more!Marcus Hammarberg
 
User stories - an introduction
User stories - an introductionUser stories - an introduction
User stories - an introductionMarcus Hammarberg
 
SpecFlow and some things I've picked up
SpecFlow and some things I've picked upSpecFlow and some things I've picked up
SpecFlow and some things I've picked upMarcus Hammarberg
 

Mehr von Marcus Hammarberg (20)

20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board20 Ideas On How To Improve Your Agile Board
20 Ideas On How To Improve Your Agile Board
 
How kanban Saved a hospital in Indonesia
How kanban Saved a hospital in IndonesiaHow kanban Saved a hospital in Indonesia
How kanban Saved a hospital in Indonesia
 
How kanban Saved a hospital in Indoneisa OreDev 2016
How kanban Saved a hospital in Indoneisa OreDev 2016How kanban Saved a hospital in Indoneisa OreDev 2016
How kanban Saved a hospital in Indoneisa OreDev 2016
 
How kanban saved a hospital in Indoneisa LKNA2016
How kanban saved a hospital in Indoneisa LKNA2016How kanban saved a hospital in Indoneisa LKNA2016
How kanban saved a hospital in Indoneisa LKNA2016
 
ca 10 minutes on effective meetings
ca 10 minutes on effective meetingsca 10 minutes on effective meetings
ca 10 minutes on effective meetings
 
10 minutes on root cause analysis
10 minutes on root cause analysis10 minutes on root cause analysis
10 minutes on root cause analysis
 
ca 15 minutes on kanban
ca 15 minutes on kanbanca 15 minutes on kanban
ca 15 minutes on kanban
 
15 minutes on impact mapping
15 minutes on impact mapping15 minutes on impact mapping
15 minutes on impact mapping
 
20 minutes on strategic plans
20 minutes on strategic plans20 minutes on strategic plans
20 minutes on strategic plans
 
10 minutes on vision
10 minutes on vision10 minutes on vision
10 minutes on vision
 
10 minutes on mission
10 minutes on mission10 minutes on mission
10 minutes on mission
 
Impact mapping @ YOW West 2015
Impact mapping  @ YOW West 2015Impact mapping  @ YOW West 2015
Impact mapping @ YOW West 2015
 
Kanban in Action - YOW West 2015
Kanban in Action - YOW West 2015Kanban in Action - YOW West 2015
Kanban in Action - YOW West 2015
 
Kanban in Action
Kanban in ActionKanban in Action
Kanban in Action
 
Pass the pennies - Lean game simulation
Pass the pennies - Lean game simulationPass the pennies - Lean game simulation
Pass the pennies - Lean game simulation
 
Numbers simulation - less is more!
Numbers simulation - less is more!Numbers simulation - less is more!
Numbers simulation - less is more!
 
User stories - an introduction
User stories - an introductionUser stories - an introduction
User stories - an introduction
 
SpecFlow and some things I've picked up
SpecFlow and some things I've picked upSpecFlow and some things I've picked up
SpecFlow and some things I've picked up
 
Specification by Example
Specification by ExampleSpecification by Example
Specification by Example
 
Kanban In Action
Kanban In ActionKanban In Action
Kanban In Action
 

Kürzlich hochgeladen

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Kürzlich hochgeladen (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

Specification by example with specflow 110217

  • 1. Specification by example with SpecFlow Marcus Hammarberg Avega Group www.marcusoft.net söndag den 20 februari 2011 (v.)
  • 2. http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257 sö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? :)
  • 3. http://www.stochasticgeometry.ie/wp-content/uploads/2009/10/snakeoil.jpg?w=257 http://www.unit5.org/debordc/MPj04071740000[1].jpg sö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? :)
  • 4. “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].jpg sö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? :)
  • 5. söndag den 20 februari 2011 (v.) My name is Marcus Hammarberg
  • 6. söndag den 20 februari 2011 (v.) I work for Avega Group as an agile coach and consultant
  • 7. söndag den 20 februari 2011 (v.) I have one wife
  • 8. söndag den 20 februari 2011 (v.) two hobbies
  • 9. söndag den 20 februari 2011 (v.) and three kids
  • 10. söndag den 20 februari 2011 (v.) I have been working as a programmer
  • 11. söndag den 20 februari 2011 (v.) since 1998 - mainly with Microsoft products
  • 12. söndag den 20 februari 2011 (v.) During the last 6 years I have been more and more interested in how you can work effective together
  • 13. söndag den 20 februari 2011 (v.) with agile methods - such as scrum
  • 14. Who are you? söndag den 20 februari 2011 (v.)
  • 15. BDD sö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
  • 16. TDD söndag den 20 februari 2011 (v.) TDD (Test driven development) is a way to write code where you start from a test describing the functionality you’re about to write. The test drives the production code from the developer. 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?
  • 17. Behaviour Driven Design sö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 language that everyone concerned can read and understand the langauge. So that we can talk about WHAT the feature does - separated from HOW.
  • 18. Outside-in development http://www.adaptivepath.com/blog/wp-content/uploads/2009/02/oi_model_inward.jpg sö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. That has 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 - this feature is done! This is called ATDD by some - Acceptance test driven development
  • 19. 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 20. What’s all these DD’s? • TDD 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 21. What’s all these DD’s? • TDD • ATDD 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 22. What’s all these DD’s? • TDD • ATDD • STDD 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 23. What’s all these DD’s? • TDD • ATDD • STDD • BDD 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 24. What’s all these DD’s? • TDD • ATDD • STDD • BDD • Specification by example 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 25. 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 or expectations before development is started - STDD - Story test driven development - don’t know much about this. Seems to be very like ATDD BDD - 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 the scenarios or examples is run in Specification by example - a way to specify something by giving concrete examples on how they should work.
  • 26. söndag den 20 februari 2011 (v.) Or you can use this great intro and skip the buzz-words altogether. From Gojko Adzic This 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 the first time. We know it never will be, but the less rework, the better.
  • 27. 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 Gregory söndag den 20 februari 2011 (v.) Or you can use this great intro and skip the buzz-words altogether. From Gojko Adzic This 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 the first time. We know it never will be, but the less rework, the better.
  • 28. Theory söndag den 20 februari 2011 (v.) Some theory on the background of Specfication by example
  • 29. User stories 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 for the function to exist. But this is, even though it’s short, still to wide and open for interpretations. Therefore user stories are often called “a placeholder for a further conversation”
  • 30. 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 for the function to exist. But this is, even though it’s short, still to wide and open for interpretations. Therefore user stories are often called “a placeholder for a further conversation”
  • 31. User stories 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 for the function to exist. But this is, even though it’s short, still to wide and open for interpretations. Therefore user stories are often called “a placeholder for a further conversation”
  • 32. 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 theoretical text... It’s much easier with a couple of pictures to guide us
  • 33. 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 be played out. They could be written with the template; Given / When / Then.
  • 34. 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 be played out. They could be written with the template; Given / When / Then.
  • 35. 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 returned 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 be played out. They could be written with the template; Given / When / Then.
  • 36. Scenario 2: Account is overdrawn past the overdraft limit Given the account is overdrawn And the card is valid When the customer requests cash Then ensure a rejection message is displayed And ensure cash is not dispensed And ensure the card is returned 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 be played out. They could be written with the template; Given / When / Then.
  • 37. 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 the system is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOW If you now only didn’t have to run the test cases ...
  • 38. 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 returned 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 the system is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOW If you now only didn’t have to run the test cases ...
  • 39. 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 the system is implemented - it’s easy to see which functionality that is included (in a release for example) - and finally it’s VAD separated from HOW If you now only didn’t have to run the test cases ...
  • 40. Wrap-up Executable specifications that verifies that the system behaves as expected, readable by all in the team, and around it söndag den 20 februari 2011 (v.) This was the promise in the outset - is it kept?
  • 41. It’s not in the tool http://www.barbellsandbacon.com/wp-content/uploads/2010/02/mlss_mario-hammer.jpg söndag den 20 februari 2011 (v.) It’s very important to remember that the main benefit is not in the tool (which we will talk about from now on). The benefit is that you get together and write down your common, shared knowledge in a well known format. In one place. That’s why anyone would dare call this a Silver Bullet
  • 42. Tools söndag den 20 februari 2011 (v.) When we have these scenarios in place it would be wonderful if we could use some kind of tool 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 can actually execute scenarios written in the Given/When/Then-syntax. This syntax is called Gherkin. For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best one is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • 43. Tools http://buyorganicvegetable.com/images/Cucumber.jpg söndag den 20 februari 2011 (v.) When we have these scenarios in place it would be wonderful if we could use some kind of tool 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 can actually execute scenarios written in the Given/When/Then-syntax. This syntax is called Gherkin. For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best one is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • 44. Tools http://buyorganicvegetable.com/images/Cucumber.jpg söndag den 20 februari 2011 (v.) When we have these scenarios in place it would be wonderful if we could use some kind of tool 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 can actually execute scenarios written in the Given/When/Then-syntax. This syntax is called Gherkin. For .NET there’s a lot of BDD frameworks that emulates Cucumber, but in my opinion the best one is SpecFlow. You can think of SpecFlow as a port of Cucumber for .NET.
  • 45. 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 step definition. The method defines what the step means; How do you define “Given I am on the Activity 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 the example
  • 46. 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 step definition. The method defines what the step means; How do you define “Given I am on the Activity 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 the example
  • 47. No really, how does it WORK? http://www.specflow.org/getfile/a67f8885-4900-4803-a972-5f3c57364097/artifacts.aspx sö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 a test-class, that contains a test for each scenario 2 - The generated code (that you never care about that code, or rather don’t touch it) it’s just there 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 step definitions in the order they are written in the scenario 4 - And your step definitions then call your application or domain.
  • 48. Step definitions http://www.treehugger.com/green%20footsteps%20generic.jpg sö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 that link on the web page (I guess) and then click it.
  • 49. Step definitions http://www.treehugger.com/green%20footsteps%20generic.jpg sö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 that link on the web page (I guess) and then click it.
  • 50. 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.jpg sö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 that link on the web page (I guess) and then click it.
  • 51. Automation http://www.cultofmac.com/wordpress/wp-content/uploads/2010/09/automator-icon.png sö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.
  • 52. Gherkin sö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 Alsak Hellesoy. We will now examine it a bit closer.
  • 53. 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.
  • 54. 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.
  • 55. 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.
  • 56. 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.
  • 57. 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.
  • 58. 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.
  • 59. 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.
  • 60. 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.
  • 61. Feature http://www.lushtshirts.co.uk/images/products/bug-feature.jpg söndag den 20 februari 2011 (v.) Features and scenarios are written in .feature. It contains an feature description and one or more 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 the scenario is executed or interpreted. It’s very important though - in order to understand the scenarios. Every feature has a title and is written after the keyword Feature:
  • 62. Feature http://www.lushtshirts.co.uk/images/products/bug-feature.jpg söndag den 20 februari 2011 (v.) Features and scenarios are written in .feature. It contains an feature description and one or more 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 the scenario is executed or interpreted. It’s very important though - in order to understand the scenarios. Every feature has a title and is written after the keyword Feature:
  • 63. Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpg söndag den 20 februari 2011 (v.) A scenario also has a title and one or more steps You can use the Friends-rule to set a good name of the scenario. You know, the episodes of Friends was called “The one where Ross and Rachel became a couple”, about half of the episodes was called that if I remember correctly :)
  • 64. Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpg söndag den 20 februari 2011 (v.) A scenario also has a title and one or more steps You can use the Friends-rule to set a good name of the scenario. You know, the episodes of Friends was called “The one where Ross and Rachel became a couple”, about half of the episodes was called that if I remember correctly :)
  • 65. Scenario http://images2.fanpop.com/images/photos/7000000/Friends-33-friends-7046166-1280-1024.jpg söndag den 20 februari 2011 (v.) A scenario also has a title and one or more steps You can use the Friends-rule to set a good name of the scenario. You know, the episodes of Friends was called “The one where Ross and Rachel became a couple”, about half of the episodes was called that if I remember correctly :)
  • 66. GIVEN WHEN THEN 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 happend The scenario is executed top down. And the Given / When / Then keyword can be repeated several 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 order you want. But then you lose any pros of the structure in the first place.
  • 67. 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 answer 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 happend The scenario is executed top down. And the Given / When / Then keyword can be repeated several 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 order you want. But then you lose any pros of the structure in the first place.
  • 68. 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 happend The scenario is executed top down. And the Given / When / Then keyword can be repeated several 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 order you want. But then you lose any pros of the structure in the first place.
  • 69. 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 the language. Try not do use AND/BUT in the When-step. Let that be a single action.
  • 70. Expressions 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 the order 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 very far. Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • 71. Expressions When I write 'My test string' in the textbox 'Test textbox' 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 the order 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 very far. Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • 72. 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 the order 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 very far. Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • 73. 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 => integer 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 the order 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 very far. Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • 74. 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 => integer 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 the order 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 very far. Also, since SpecFlow 1.4, you get intellisense for the step definitions you already written
  • 75. Background sö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
  • 76. Hooks sö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
  • 77. Hooks sö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
  • 78. Tags 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 the scenario. 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 the scenario or feature has a certain tag.
  • 79. Tags 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 the scenario. 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 the scenario or feature has a certain tag.
  • 80. @ignore 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 the scenario. 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 the scenario or feature has a certain tag.
  • 81. 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 the scenario. 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 the scenario or feature has a certain tag.
  • 82. 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 a SpecFlow Table that has values for columns and rows. From that table you can read a data.
  • 83. 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 a SpecFlow Table that has values for columns and rows. From that table you can read a data.
  • 84. [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 a SpecFlow Table that has values for columns and rows. From that table you can read a data.
  • 85. SpecFlow.Assist söndag den 20 februari 2011 (v.) Working with tables can be quite messy. But in this namespace (SpecFlow.Assist) there’s some 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
  • 86. Scenario outline sö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 same scenario. This example will create 5 test that performs the calculation. How this is done depends on the testrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTest creates several tests.
  • 87. Scenario outline sö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 same scenario. This example will create 5 test that performs the calculation. How this is done depends on the testrunner you’re using; NUnit creates TestCases that sends data to the unit test while MsTest creates several tests.
  • 88. Langauge sö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 specification project.
  • 89. ScenarioContext.Current söndag den 20 februari 2011 (v.) ScenarioContext is a small dictionary that is used to send data between your steps. It’s much better 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, function See https://github.com/marcushammarberg/ProgressiveNetDemos/tree/master/Specs/ 031ScenarioContext
  • 90. AvegaCoach Activity Log sö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.
  • 91. On with the code! http://burningbird.net/photos/thumb-victwait.jpg söndag den 20 februari 2011 (v.) On to the code!
  • 92. Learn more söndag den 20 februari 2011 (v.)
  • 93. Learn more • http://blog.dannorth.net/introducing-bdd/ söndag den 20 februari 2011 (v.)
  • 94. Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ söndag den 20 februari 2011 (v.)
  • 95. Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow söndag den 20 februari 2011 (v.)
  • 96. Learn more • http://blog.dannorth.net/introducing-bdd/ • http://www.specflow.org/ • https://github.com/techtalk/SpecFlow • http://github.com/techtalk/SpecFlow-Examples söndag den 20 februari 2011 (v.)
  • 97. 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 söndag den 20 februari 2011 (v.)
  • 98. 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 söndag den 20 februari 2011 (v.)
  • 99. 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/ ProgressiveNetDemos söndag den 20 februari 2011 (v.)
  • 100. And even more söndag den 20 februari 2011 (v.)
  • 101. And even more söndag den 20 februari 2011 (v.)
  • 102. And even more söndag den 20 februari 2011 (v.)
  • 103. And even more söndag den 20 februari 2011 (v.)
  • 104. And even more söndag den 20 februari 2011 (v.)
  • 105. www.marcusoft.net marcus.hammarberg@avegagroup.se söndag den 20 februari 2011 (v.) Thanks for listening
  • 106. www.marcusoft.net marcus.hammarberg@avegagroup.se söndag den 20 februari 2011 (v.) Thanks for listening
  • 107. söndag den 20 februari 2011 (v.) The end