LightBDD Configuration - LightBDD/LightBDD GitHub Wiki
Page version: 3.x / 2.x
The LightBDD is configurable, and configuration can be applied in code.
The concept of LightBDD scope has been introduced to explicitly control when LightBDD should initialize and cleanup, where:
- LightBDD scope initialization has to happen before any tests being executed,
- LightBDD scope cleanup has to happen after all tests being executed.
The LightBDD configuration happens now during LightBDD scope initialization and LightBddConfiguration
class is used in this process.
Due to the different nature of underlying test frameworks, the LightBDD scope definition looks different, however in all cases it is possible to get access to LightBddConfiguration
instance.
The below examples shows how to configure LightBDD integrated with different runners.
using LightBDD.Core.Configuration;
using Example.LightBDD.NUnit3;
using LightBDD.Framework.Configuration;
using LightBDD.Framework.Reporting.Formatters;
using LightBDD.NUnit3;
[assembly: ConfiguredLightBddScope] // the configured scope is applied on assembly
namespace Example.LightBDD.NUnit3
{
class ConfiguredLightBddScopeAttribute : LightBddScopeAttribute
{
protected override void OnConfigure(LightBddConfiguration configuration)
{
// some example customization of report writers
configuration
.ReportWritersConfiguration()
.AddFileWriter<PlainTextReportFormatter>("~\\Reports\\FeaturesReport.txt");
}
protected override void OnSetUp()
{
// additional code that has to be run before any LightBDD tests
}
protected override void OnTearDown()
{
// additional code that has to be run after all LightBDD tests
}
}
}
Note: Please note that OnSetUp()
/ OnTearDown()
methods can be overridden to run additional code before any tests or after all tests are executed. It is worth to note that OnTearDown()
method is executed before any reports are generated.
using LightBDD.Core.Configuration;
using Example.LightBDD.XUnit2;
using LightBDD.Framework.Configuration;
using LightBDD.Framework.Reporting.Formatters;
using LightBDD.XUnit2;
[assembly: ConfiguredLightBddScope] // the configured scope is applied on assembly
namespace Example.LightBDD.XUnit2
{
class ConfiguredLightBddScopeAttribute : LightBddScopeAttribute
{
protected override void OnConfigure(LightBddConfiguration configuration)
{
// some example customization of report writers
configuration
.ReportWritersConfiguration()
.AddFileWriter<PlainTextReportFormatter>("~\\Reports\\FeaturesReport.txt");
}
protected override void OnSetUp()
{
// additional code that has to be run before any LightBDD tests
}
protected override void OnTearDown()
{
// additional code that has to be run after all LightBDD tests
}
}
}
Note: Please note that OnSetUp()
/ OnTearDown()
methods can be overridden to run additional code before any tests or after all tests are executed. It is worth to note that OnTearDown()
method is executed before any reports are generated.
using LightBDD.Core.Configuration;
using LightBDD.Framework.Configuration;
using LightBDD.Framework.Reporting.Formatters;
using LightBDD.MsTest3;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Example.LightBDD.MsTest3
{
[TestClass] // please note that [TestClass] attribute is required here
public class LightBddIntegration
{
// the scope is initialized and cleaned-up explicitly by methods annotated with [AssemblyInitialize] / [AssemblyCleanup] attributes.
[AssemblyInitialize]
public static void Setup(TestContext testContext) { LightBddScope.Initialize(OnConfigure); }
[AssemblyCleanup]
public static void Cleanup() { LightBddScope.Cleanup(); }
private static void OnConfigure(LightBddConfiguration configuration)
{
// some example customization of report writers
configuration
.ReportWritersConfiguration()
.Clear()
.AddFileWriter<PlainTextReportFormatter>("~\\Reports\\FeaturesReport.txt");
}
}
}
using LightBDD.Core.Configuration;
using LightBDD.Fixie3;
using LightBDD.Framework.Configuration;
using LightBDD.Framework.Reporting.Formatters;
namespace Example.LightBDD.Fixie3
{
internal class ConfiguredLightBddScope : LightBddScope
{
protected override void OnConfigure(LightBddConfiguration configuration)
{
configuration
.ReportWritersConfiguration()
.AddFileWriter<PlainTextReportFormatter>("~\\Reports\\FeaturesReport.txt");
}
protected override void OnSetUp()
{
// additional code that has to be run before any LightBDD tests
}
protected override void OnTearDown()
{
// additional code that has to be run after all LightBDD tests
}
}
}
-
ReportWritersConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure reports that will be generated after all tests (described in Generating Reports section). -
CultureInfoProviderConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure culture that would be used to render feature/scenario/steps details. -
StepTypeConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure predefined step types and repeated step replacement (described in Scenario Steps Definition section). It allows also to specify a method determining if given lambda parameter name should be used as step type or not. -
ExecutionExtensionsConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to enable additional LightBDD extensions for scenario and step execution (described in Extending test behavior section). -
ExceptionHandlingConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure what failure scenario/step details are captured. -
NameFormatterConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure feature/scenario/step name formatting. -
ValueFormattingConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure default formatters used to format scenarios/step parameters. -
DependencyContainerConfiguration()
Namespace: LightBDD.Core.Configuration
Allows to configure DI container used by LightBDD (described in DI Containers section). -
FeatureProgressNotifierConfiguration()
Namespace: LightBDD.Framework.Configuration
Allows to configure feature progress notification (described in Test Progress Notification section). -
ScenarioProgressNotifierConfiguration()
Namespace: LightBDD.Framework.Configuration
Allows to configure scenario progress notification (described in Test Progress Notification section).
Continue reading: Visual Studio Extensions