4
votes

specflow looks like a solution I want my team to consider using. My manager, however, isn't real fond of BDD-style tests. Because of the nice integration of specflow with visual studio, I'm wondering if I could leverage the specflow framework while allowing a less bdd-style form of tests.

For example, instead of writing a test like:

Scenario: Help->About
  Given a user is logged in to "http://..." as "user/password"
    And they are on the page titled "Home"
   When I click on "about"
   Then I should see a window titled "about"

... I would like to write it as:

Scenario: Help->About
  log in to "http://..." as "user/password"
  click on the "About" link
  assert "About" window should be visible

In other words, must I use keywords like Given, Then, etc. or is specflow able to handle steps that don't begin with those words?

2

2 Answers

1
votes

Specflow uses the Given, When and Then keywords in the code generator to generate a test case like this:

    [NUnit.Framework.TestAttribute()]
    [NUnit.Framework.DescriptionAttribute("See the content of a message")]
    public virtual void SeeTheContentOfAMessage()
    {
        TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Help->About", ((string[])(null)));
        this.ScenarioSetup(scenarioInfo);
        testRunner.Given("a user is logged in to \"http://\" as user/password");
        testRunner.When("I click on About"); 
        testRunner.Then("I should see a window titled about");
        testRunner.CollectScenarioErrors();
    }

The only way to change the tests to the way you described is by changing the code generator. The TryParseStepKeyword() method in GherkinDialect is a good start

0
votes

I think a lot of it is how you interpret the Given, When and Then. The best approach we found was Given should be preparing the state for the test. When should be the action you are testing against and Then should be the verification. When you think of it from this approach both example are very similar. Personally i like the more generic style of the second one. This way your not tying your feature to a specific set of steps, instead your testing the behaviour. In saying that it really wouldn't take more to would your tests like that. for example.

Scenario: Help->About
Given a user is logged in
When you navigate to the the About page
Then the about information should be displayed

I try not to use specific actions like click. In the end its up to you how to word the steps but specflow does use the Given/When/Then for code generation. You don't need to use all though.