A series of utils to make it easier to write custom testing tools in .net using a BDD approach.
$ dotnet add package BorsukSoftware.Testing.BDDThis project provides a series of utility classes to support Behavior Driven Development (BDD) style integration testing in .NET projects.
Due to the nature of integration tests, where each system being tested may have different requirements and setup, this library focuses on providing a flexible framework for defining and executing test steps, rather than a rigid testing structure. We provide a sample usage application to demonstrate how to use the library effectively / provide a reference implementation to simplify the creation of appropriate tooling for your projects.
Note that we have extended the Cucumber language to allow, by convention, more complicated step definitions. This allows for a more expressive and powerful way to define test steps, while still adhering to the principles of BDD. This level of granularity might not be necessary for all projects, but it can be very useful in complex integration testing scenarios where the product being tested actually requires some of that internal knowledge.
Each step definition is a static method, decorated with a [Step("step text")] attribute. The step text can include parameters, denoted by curly braces {}. The method will also take a user-defined and supplied context object which manages the state for the test as well as connection details for any external services required (e.g. DBs, APIs, Selenium / Appium instances). Body parameters are denoted by the [FromBody] attribute.
The StepFactory is the key component of the library.
We provide a sample usage application and will update this README with more information soon.
public static class ProductSteps
{
[Step("admin user creates a product with alias {productAlias}")]
public static async Task AdminUserCreatesProduct2(
IIntegrationTestContext context,
string productAlias,
[FromBody] Steps.Models.NewProductModel productModel)
{
// Implementation here
}
}
var stepFactory = new BorsukSoftware.Testing.BDD.StepFactory<IIntegrationTestContext>();
stepFactory.RegisterAssembly(typeof(IntegrationTestRunner).Assembly);
// Populate your context with any required data
var context = new IntegrationTestContext();
foreach (var step in stepsToRun)
{
Console.WriteLine($" => '{step.Text}'");
await stepFactory.Process(testContext, step.Text, step.Argument);
}