Give a try to BDDfy for .NET

Last week I wanted to try to use Double TDD  approach, looking at Waldemar Mękal’s presentation on dotNetConf 2015th conference I saw that he uses BDD in his double TDD.

I decided to write some words about BDDfy which is the simplest BDD framework for .NET or so project creators wrote.

Behaviour-driven Development(BDD) is a software development process that emerged from test-driven development. Behavior-driven development combines the general techniques and principles of TDD with ideas from domain-driven design and object-oriented analysis and design to provide software development and management teams with shared tools and a shared process to collaborate on software development” wikipedia says.

I installed BDDfy via NuGet Console:
Install-Package TestStack.BDDfy

And write sample tests based on these requirements(mapped from Waldek presentation):
#1
Given there are no companies
When I go to companies page
Then I see a text 'There are no companies loaded yet.'

#2
Given there are defined companies
When I go to companies page
Then I see full list of defined companies

First requirement implementation using BDDfy fluent API:

[Fact]
public void NoCompaniesInTheSystem()
{
    new CompaniesTestsContext()
        .Given(c => c.ThereAreNoCompanies())
        .When(c => c.IGoToCompaniesPage())
        .Then(c => c.ISeeATextNoCompaniesLoadedYet())
        .TearDownWith(c => c.Dispose())
        .BDDfy();
}

You can see that above test is self descriptive and describes behavior, which is the basis of BDD.

Second requirement implementation is very similar:

[Fact]
public void ManyCompaniesInTheSystem()
{
    new CompaniesTestsContext()
        .Given(c => c.ThereAreCompanies())
        .When(c => c.IGoToCompaniesPage())
        .Then(c => c.ISeeATextManyCompaniesLoaded())
        .TearDownWith(c => c.Dispose())
        .BDDfy();
}

Both cases using CompaniesTestsContext class, which hides implementation details. This class contains mentioned by me in previous post helper classes Client(based on Coypu) and SystemUnderTest(based on Microsoft.DotNet.Hosting).

Leave a Reply

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>