Blog

Automated Software Testing with SpecFlow

SpecFlow is open source and provided under a BSD license. SpecFlow uses the official Gherkin parser and provides integration to the .NET framework, Silverlight, Windows Phone, and Mono for automated software testing.

SpecFlow, also known as Cucumber for .NET is an open-source tool used for automating .NET applications. It is a Behavior Driven Development or BDD tool. These tools are bridges between the business language and technical language. Using these tools, the test-cases for automated software testing with SpecFlow are written in English-like language understandable by all the stakeholders of the project, developers and non-developers alike.

Cucumber is a Ruby tool that offers a natural language interface to specify behaviors in terms of “Given, When, Then” or GWT sentence fragments. This language is called Gherkin. The feature film is a plain text file containing a set of scenario definitions written in Gherkin.

SPEC Flow

SpecFlow – How it Works

SpecFlow can be integrated with a number of IDEs including Visual Studio, SharpDevelop and MonoDevelop to roll out automated testing. It uses gherkin language for writing the test scenarios using keywords Given, When and Then. The test scripts can be written in any popular language like C#,Visual Basic .NET, Boo, F#, IronPython and IronRuby.

A feature file created for writing the test scenarios. This file contains the name of the feature to be tested, test scenarios and when to execute the test scripts. The test scripts are prepared in a class based on the test scenarios created. Later these test scripts can be executed as unit tests using NUnit or MTest. The result of the tests run is available. The tests can be passed, failed or inconclusive.

A distinct advantage of BDD tools it has the option of generating suggestions for writing test scripts. If the tests are run without providing the test scripts, the tests will be marked as inconclusive and the suggestions for writing the test scripts will be provided.

With .NET in SpecFlow

SpecFlow is an open-source .NET tool that allows writing of test specifications using entirely Cucumber compatible Gherkin syntax and beats Cucumber at its own game. Since Cucumber is a generic framework which can be used for all the languages while SpecFlow is specific to .NET framework, SpecFlow offers distinctive advantages over Cucumber.

Benefits of using SpecFlow for Automated Software Testing

      • Tests can be prioritized using SpecFlow while Cucumber does not provide the functionality of prioritizing tests. This can be beneficial if only some of the scenarios are to be tested in one run.
      • In SpecFlow, parameters passed in the tests can be mapped to the text instructions avoiding the need to the sequence of parameters in text. It can be mapped irrespective of the sequence. This feature is not supported in Cucumber.
      • Scoping functionality is available in Specflow which is not present in Cucumber. By defining the Scope, the same test definition can be used for executing multiple test scripts for automated software testing with SpecFlow. For example, if UI and functional test scripts are to be executed for the same test scenario, then in Specflow there is no need to create two different scenarios. Tests can be executed by using scope. While in Cucumber, for every test script there must be a different scenario.
      • When test scripts are being written for a very large project, there are hundreds of test scenarios. Creating test scripts for these scenarios and remembering them while writing becomes cumbersome. SpecFlow provides a feature named Auto-Complete, with Visual Studio integration, using which the phrases can be automatically completed in test scripts. Only by typing a single word, a phrase can be selected.
      • Cucumber does not provide any such feature and this is one major drawback for this tool for automated software testing.
      • SpecFlow very naturally integrates with Visual Studio, and new feature files are created very easily by File/New templates.
      • SpecFlow gives complete Visual Studio debugger support, allowing setting of breakpoints on Given/When/Then lines in the feature files and step through their execution.
      • All step definitions are implemented in any .NET language.
      • When a project containing SpecFlow feature files is compiled, the output is a NUnit test assembly. Any NUnit-compatible test runner or existing CI infrastructure can be then used to execute the test specifications with no additional configuration to conduct the automated software testing.

On A Parting Note

An appropriate and prudent test strategy is the call of the day today. Software Testing Solutions ensure a right mix of Manual and Automated Software Testing and provide support through the Testing Life Cycle. The unbiased test reports help smoother implementations with near zero post-delivery defects and higher customer satisfaction.

Request a FREE POC to Test drive our services.

Author: SPEC QA