Skip to content
Suremaker edited this page Feb 28, 2017 · 3 revisions

Page version: 2.x / 1.x

The acceptance tests written with LightBDD are represented by partial feature class, split between two files:

  • acceptance tests definition part containing easy to read scenarios,
  • implementation part containing scenario test implementation.

The first part contains:

  • optional feature description and label,
  • list of scenario methods with optional label and body with Runner executing scenario steps.
[TestFixture]
[FeatureDescription(
@"In order to access personal data
As an user
I want to login into system")] //feature description
[Label("Story-1")]
public partial class Login_feature //feature name
{
	[Test]
	[Label("Ticket-1")]
	public void Successful_login() //scenario name
	{
		Runner.RunScenario(

			Given_the_user_is_about_to_login, //scenario steps
			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);
	}
}

The second part contains:

  • implementation of all step methods
  • set up / tear down methods
  • inheritance of FeatureFixture base class (it is strongly recommended, however it is possible also to not have it - please see Feature Fixture section).
public partial class Login_feature : FeatureFixture
{
	/* scenario data */
	/* set up / tear down methods */

	private void Given_the_user_is_about_to_login()
	{
		_loginService = new LoginService();
		_loginService.AddUser(_validUserName, _validPassword);
		_loginRequest = new LoginRequest();
	}
	
	private void When_the_user_clicks_login_button()
	{
		_loginResult = _loginService.Login(_loginRequest);
	}

	private void Then_the_login_operation_should_be_successful()
	{
		Assert.That(_loginResult.IsSuccessful, Is.True);
	}

	/* other step definitions */
}

Please note that the project contains set of templates that can be used with Visual Studio to create Feature tests. Please check Templates folder for details how to install them.

Please also note that LightBDD supports various step method signatures, which are described in Scenario Steps Definition section.

Test running:

LightBDD bases on underlying test framework (NUnit / MbUnit / MsTest / xUnit), so the tests can be run in the same way as regular unit tests.

During run, the test progress would be printed on console, like:

FEATURE: [Story-1] Login feature
  In order to access personal data
  As an user
  I want to login into system

SCENARIO: [Ticket-1] Successful login
  STEP 1/6: GIVEN the user is about to login...
  STEP 1/6: GIVEN the user is about to login (Passed after 9ms)
  STEP 2/6: AND the user entered valid login...
  STEP 2/6: AND the user entered valid login (Passed after <1ms)
  STEP 3/6: AND the user entered valid password...
  STEP 3/6: AND the user entered valid password (Passed after <1ms)
  STEP 4/6: WHEN the user clicks login button...
  STEP 4/6: WHEN the user clicks login button (Passed after 182ms)
  STEP 5/6: THEN the login operation should be successful...
  STEP 5/6: THEN the login operation should be successful (Passed after 5ms)
  STEP 6/6: AND a welcome message containing user name should be returned...
  STEP 6/6: AND a welcome message containing user name should be returned (Passed after 14ms)
  SCENARIO RESULT: Passed after 233ms

After all tests are finished, FeaturesSummary.xml would be created in project bin folder with scenario execution details.

<?xml version="1.0" encoding="utf-8"?>
<TestResults>
  <Summary TestExecutionStart="2015-06-24T21:52:07.0287745Z" TestExecutionTime="PT0.233761S">
    <Features Count="1" />
    <Scenarios Count="1" Passed="1" Bypassed="0" Failed="0" Ignored="0" />
    <Steps Count="6" Passed="6" Bypassed="0" Failed="0" Ignored="0" NotRun="0" />
  </Summary>
  <Feature Name="Login feature" Label="Story-1">
    <Description>In order to access personal data
As an user
I want to login into system</Description>
    <Scenario Status="Passed" Name="Successful login" Label="Ticket-1" ExecutionStart="2015-06-24T21:52:07.0287745Z" ExecutionTime="PT0.233761S">
      <Category Name="Security" />
      <Step Status="Passed" Number="1" Name="GIVEN the user is about to login" ExecutionStart="2015-06-24T21:52:07.0327785Z" ExecutionTime="PT0.0091674S">
        <StepName StepType="GIVEN" Format="the user is about to login" />
      </Step>
      <Step Status="Passed" Number="2" Name="AND the user entered valid login" ExecutionStart="2015-06-24T21:52:07.057792Z" ExecutionTime="PT0.0003209S">
        <StepName StepType="AND" Format="the user entered valid login" />
      </Step>
      <!- ... ->
    </Scenario>
  </Feature>
</TestResults>

Please note that while creating FeaturesSummary.xml is default behavior, it can be customized in app.config file or in code to generate other types of reports like HTML (see example file) - please see Generating Reports section for details.

Continue reading: Tests structure and conventions

Clone this wiki locally