Find bugs before they happen.

Are you tired of finding bugs in your software that occurred due to misunderstandings between your team and the customer that led to your automated tests falling short in covering vital cases?

Getting started Find out how

How SpecFlow helps you handle these situations:

1
Discover: Find details by sharing examples with business
2
Formulate: Write test cases in a natural language
3
Automate: Avoid regression by automating test cases

As a developer, you struggle with situations like:

Natural Language for Naming Tests

Situation:

You try to use best practice naming conventions for your test methods, but you are still not happy with the result.

without SpecFlow
[Fact]
public void GetShoppingCart_EmptySession_EmptyShoppingCart()
// Empty Session = first time visit on page

Regardless of how much you try to rename it to make more sense, it will not get better. Eventually, you give up and end up with method names of your automated tests:

Let’s hope nobody deletes that comment...

with SpecFlow
Scenario: New User starts with an empty Shopping Cart
 
A user is a new User, when they visit the page for the first time, which is detected via Cookies

You write a normal sentence to describe what your test is doing.

With the added flexibility of adding a description to each test and not being limited to just English


Easy use of Examples

Situation:

You finally got some concrete examples on how the application should behave

without SpecFlow
[Theory]
[InlineDate(”Domain“, ”’Domain Driven Design‘“)]
[InlineDate(”Windows Communication”, ”’Briefing the Communication Gap‘, ’Inside Windows SharePoint Services‘“)]
public void Search_MatchTitle(string serachString, string expectedBookTitles)

Struggle with translating examples into automated tests (e.g. example table handling) and wonder if your code still reflects the example. Can your stakeholder read code?

with SpecFlow
Scenario Outline: Simple search
 
When I search for books by the phrase ''
Then the list of found books should contain only:
 
Examples:
| search phrase
|
books
|
| Domain
|
'Domain Driven Design'
|
| Windows Communication
|
'Bridging the Communication Gap', 'Inside Windows SharePoint Services'
|

Define your examples in a nice, easily readable way with tables, readable for all stakeholders.


Make the value of testing transparent

Situation:

You want to start writing automated tests, but you are stopped by the product owner, because they see no value in them.

without SpecFlow

Within the Developer's IDE 856/895 passed tests are reported.

with SpecFlow

Stakeholders discover the value of testing with their browser, which displays an auto-generated up-to-date documentation of your automated tests.


Explaining how the application works

Situation:

Situation: A feature is in production for months and you have already forgotten most of the details. Suddenly the product owner stands next to your table and wants to know some details of the feature.

without SpecFlow

You block 4 hours of your time to dig through the code and find the answer out on your own. Then you have an one-hour meeting to explain it to your product owner

with SpecFlow

You point them to your understandable and readable test cases, where they are able to easily fnd answers to their questions.

Try SpecFlow - #1 open source .NET solution for automated testing

Getting started

Use established Test Automation Libraries

Browser Testing with Selenium

Write your Test scenarios without the need to mention any Selectors or Element Ids. You can hide this implementation details in your automation layer.

Scenario: Type should offer a list of unique entries
When the submission page is open
Then you can choose from the following Types:
| Typename
|
| Blog Posts
|
| Books
|
| Presentations
|
| Videos
|
| Podcasts
|
| Examples
|
[When(@"the submission page is open")]
public void WhenTheSubmissionPageIsOpen()
{
_webDriverDriver.WebDriver.Url = _webServerDriver.Hostname;
}
[Then(@"you can choose from the following Types:")]
public void ThenYouCanChooseFromTheFollowingTypes(Table table)
{
var expectedEntries = table.CreateSet();
var typeSelectEntry = _webDriverDriver.WebDriver.FindElement(By.Id("txtType"));
var webElements = new SelectElement(typeSelectEntry).Options.ToList();
var actualTypenameEntries = webElements.Select(i => new TypenameEntry {Typename = i.Text}).ToList();
actualTypenameEntries.Should().BeEquivalentTo(expectedEntries);
}

API Testing with RestSharp

With SpecFlow you don’t need to work with raw JSON or any other messaging format in your tests.

You can use SpecFlow together with RestSharp to have a nice and clean interface to test your APIs.

Scenario: Type should offer a list of unique entries
When the submission page is open
Then you can choose from the following Types:
| Typename
|
| Blog Posts
|
| Books
|
| Presentations
|
| Videos
|
| Podcasts
|
| Examples
|
[Then(@"you can choose from the following Types:")]
public void ThenYouCanChooseFromTheFollowingTypes(Table table)
{
var typenameEntries = table.CreateSet();
var restClient = new RestClient(_webServerDriver.Hostname);
var restRequest = new RestRequest("api/AvailableTypes", DataFormat.Json);
 
var restResponse = restClient.Get(restRequest);
 
restResponse.IsSuccessful.Should().BeTrue();
var actualTypes = restResponse.Data.Types;
var expectedTypes = typenameEntries.Select(i => i.Typename);
actualTypes.Should().BeEquivalentTo(expectedTypes);
}

Popular .NET Testing Tools

SpecFlow builds upon proven .NET testing tools. You can still use your beloved tools.

MSTest
using Microsoft.VisualStudio.TestTools.UnitTesting;
[Binding]
public class MyStepDefs
{
private readonly TestContext _testContext;
public MyStepDefs(TestContext testContext)
{
_testContext = testContext;
}
[Given("a step")]
public void GivenAStep()
{
_testContext.WriteLine("I am using MSTest);
}
}
using Xunit.Abstractions;
[Binding]
public class BindingClass
{
private ITestOutputHelper _testOutputHelper;
public BindingClass(ITestOutputHelper testOutputHelper)
{
_testOutputHelper = testOutputHelper;
}
[When(@"I do something")]
public void WhenIDoSomething()
{
_testOutputHelper.WriteLine("I am using xUnit");
}
}
[Then(@"my total score should be (\d+)")]
public void ThenMyTotalScoreShouldBe(int score)
{
NUnit.Framework.Assert.That(score, Is.EqualTo(_game.Score));
}

SpecFlow works on every current .NET implementation

  • .NET Framework
  • .NET Core
  • .NET

on any supported operating system

  • Windows
  • MacOS
  • Linux

in your favorite IDE

  • Visual Studio
  • JetBrains Rider
  • VS Code