Quick Start

Wojtek edited this page Jul 20, 2018 · 29 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
{
	[Scenario]
	[Label("Ticket-1")]
	[ScenarioCategory(Categories.Security)]
	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. To use them, please install LightBDD for Visual Studio extension from Visual Studio Marketplace.

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

Choosing integration

LightBDD bases on underlying test framework (NUnit / MsTest.TestFramework / xUnit / Fixie) to run the tests.

In order to integrate with chosen test framework, one of the following nuget package has to be added to the test project:

  • LightBDD.NUnit3
  • LightBDD.NUnit2
  • LightBDD.XUnit2
  • LightBDD.MsTest2
  • LightBDD.Fixie2

After chosen package is added, please add following code to the test assembly to enable the integration:

  • For NUnit 2/3 or xUnit 2 integration: [assembly: LightBddScope]
  • For MsTest 2 integration:
    [TestClass]
    public class LightBddIntegration
    {
        [AssemblyInitialize]
        public static void Setup(TestContext testContext) { LightBddScope.Initialize(); }
        [AssemblyCleanup]
        public static void Cleanup() { LightBddScope.Cleanup(); }
    }
  • For Fixie 2 integration:
    internal class WithLightBddConventions : LightBddDiscoveryConvention
    {
    }
    
    internal class ConfiguredLightBddScope : LightBddScope
    {
    }

If tests are run without integration in place, their execution will fail with message like following one (NUnit3 example):

LightBddScopeAttribute is not defined in the project. Please ensure that following attribute, 
or attribute extending it is defined at assembly level: [assembly:LightBddScopeAttribute]

More information about supported test frameworks, differences and integration details can be found on Test Framework Integrations page.

Running tests

After underlying test framework is chosen, the LightBDD tests can be run in exactly the same way as regular tests in that framework.

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

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, Reports\FeaturesReport.xml and Reports\FeaturesReport.html will be created in project output folder with scenario execution details.

To see the full HTML report, please take a look (here). To see the full XML report, please take a look (here).

Please note that while creating FeaturesReport.xml and FeaturesReport.html is default behavior, it can be customized in LightBDDScope setup - please see Generating Reports section for details.

Continue reading: Tests structure and conventions

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.