LightBDD 1.x logo
LightBDD

LightBDD 1.7.0

It was a while since I have written a last post.
During this time many things happened, including a fact, that I was implementing new requirements for LightBDD.

Finally, since 21st of June, a new LightBDD version 1.7.0 is available for download on NuGet.

So what’s new:

xUnit support

Yes, since this version, there is a LightBDD.XUnit package, that supports writing and executing test scenarios with xUnit 2.0 (.NET 4.5.1). It means also that scenario tests can be executed in parallel with full support from Visual Studio and Resharper!

The project wiki page contains information about integration with xUnit, the adequate example project is present in project repository, as well as Templates folder and Visual Studio Gallery extension package has been updated to support it.

The integration with xUnit was interesting in a few aspects.

First of all, xUnit 2.0 supports parallel test execution. While LightBDD supports concurrent execution since its very early versions (it was always possible to run MbUnit tests in parallel), there was no decent support from newer Visual Studio / Resharper versions to run them. With xUnit it is possible.

Because of this feature, xUnit designers decided to not capture a System.Console output during test execution. Instead, they offer an ITestOutputHelper interface that has to be used to capture test output in order to display it in Visual Studio test windows. Later, I have found however that xunit console runner does not use this interface, but prints System.Console output. I have noticed also that standard progress printed by ConsoleProgressNotifier is unreadable because multiple tests report their progress at the same time.
An ability to print test execution progress is one of the important LightBDD features, that is why, I had to solve both of those issues. Finally, I have implemented a few more versions of IProgressNotifier interface, and configured LightBDD.XUnit to work properly with both, Visual Studio and console runner – more details are provided on wiki page.

The second problem with xUnit was that it does not support Assert.Ignore() calls to stop test execution and make the test ignored at run time. This feature is crucial for LightBDD, because it allows to execute all already implemented steps in given scenario, even if not entire scenario is fully implemented. It gives a better traceability of scenario implementation progress.
To make it working, I had to extend xUnit a little bit – I have added a [Scenario] attribute, which should be used instead of [Fact] or [Theory] attributes, and a ScenarioAssert.Ignore() method allowing to ignore test execution at run time. Hopefully, the xUnit has an amazing extensibility points, which all are supported natively by test runners and Resharper. Only because of that, I was able to implement ScenarioAssert.Ignore() for LightBDD.XUnit integration.

So finally, the test written with LightBDD.XUnit looks like that:

[FeatureDescription(
@"In order to buy products
As a customer
I want to add products to basket")]
[Label("Story-4")]
public partial class Basket_feature
{
    [Scenario] //LightBDD specific test scenario
    [Label("Ticket-6")]
    [ScenarioCategory(Categories.Sales)]
    public void No_product_in_stock()
    {
        Runner.RunScenario(
            Given_product_is_out_of_stock,
            When_customer_adds_it_to_the_basket,
            Then_the_product_addition_should_be_unsuccessful,
            Then_the_basket_should_not_contain_the_product);
    }
}

Steps auto-grouping

Steps auto-grouping was a requirement posted on the LightBDD project page.

With this version of LightBDD, if a consecutive steps start with the same type, e.g. GIVEN, WHEN, THEN, SETUP, all except first step would be renamed to AND:

Runner.RunScenario(

    Given_the_user_is_about_to_login,
    Given_the_user_entered_valid_login,
    Given_the_user_entered_valid_password,
    When_the_user_clicks_login_button,
    Then_the_login_operation_should_be_successful,
    Then_a_welcome_message_containing_user_name_should_be_returned);
GIVEN the user is about to login
AND the user entered valid login
AND the user entered valid password
WHEN the user clicks login button
THEN the login operation should be successful
AND a welcome message containing user name should be returned

More information about auto-grouping (and step syntax mixing) is available on wiki page.

Runtime comments for steps

This was an another requirement posted on the project page.

Since this version, it is possible to use StepExecution.Comment(), StepExecution.CommentFormat() methods to comment currently executed step, where those comments would be included in execution reports – more on wiki page.

Visual Studio Gallery extension

Since version 1.6.1 it was possible to install LightBDD for Visual Studio extension from Visual Studio Gallery. With this version, it has been extended with Project and Item templates allowing to write test scenarios in xUnit.

And more improvements

To read all the changes made in version 1.7.0, please feel free to take a look at Changelog.txt file.

Finally, I would be happy to announce that there is a LightBDD framework blog post on Wonga company blog for you to read!

Happy testing!