Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

SpecFlow plugin that enables to use Microsoft.Extensions.DependencyInjection for resolving test dependencies.

License

Notifications You must be signed in to change notification settings

solidtoken/SpecFlow.DependencyInjection

Repository files navigation

Warning

This plugin has been ported to Reqnroll and will no longer be maintained.

SpecFlow.DependencyInjection

GitHub License GitHub Issues Azure Build NuGet Package

SpecFlow plugin that enables to use Microsoft.Extensions.DependencyInjection for resolving test dependencies.

Currently supports (in preview):

Based on SpecFlow.Autofac. Listed on Available Plugins for SpecFlow.

Usage

Install plugin from NuGet into your SpecFlow project.

PM> Install-Package SolidToken.SpecFlow.DependencyInjection

Create a static method in your SpecFlow project that returns a Microsoft.Extensions.DependencyInjection.IServiceCollection and tag it with the [ScenarioDependencies] attribute. Configure your test dependencies for the scenario execution within this method. Step definition classes (i.e. classes with the SpecFlow [Binding] attribute) are automatically added to the service collection.

A typical dependency builder method looks like this:

[ScenarioDependencies]
public static IServiceCollection CreateServices()
{
    var services = new ServiceCollection();
    
    // TODO: add your test dependencies here

    return services;
}

Refer to SpecFlow.DependencyInjection.Tests for an example.