Git Product home page Git Product logo

specflow.autofac's Introduction

SpecFlow.Autofac is now part of SpecFlow!

Sources for it are here: https://github.com/techtalk/SpecFlow/tree/master/Plugins/SpecFlow.Autofac.SpecFlowPlugin Please open Issues and Pull Request in the SpecFlow repro.

SpecFlow.Autofac

SpecFlow plugin for using Autofac as a dependency injection framework for step definitions.

Currently supports

  • SpecFlow v2.1
  • Autofac v3.5.2 or above

License: Apache (https://github.com/gasparnagy/SpecFlow.Autofac/blob/master/LICENSE)

NuGet: https://www.nuget.org/packages/SpecFlow.Autofac

See my blog post (http://gasparnagy.com/2016/08/specflow-tips-customizing-dependency-injection-with-autofac/) for more information and background, you can also look at the complete example at https://github.com/gasparnagy/SpecFlow.Autofac/tree/master/sample/MyCalculator.

Build status

Usage

Install plugin from NuGet into your SpecFlow project.

PM> Install-Package SpecFlow.Autofac

Create a static method somewhere in the SpecFlow project (recommended to put it into the Support folder) that returns an Autofac ContainerBuilder and tag it with the [ScenarioDependencies] attribute. Configure your dependencies for the scenario execution within the method. You also have to register the step definition classes, that you can do by either registering all public types from the SpecFlow project:

builder.RegisterAssemblyTypes(typeof(YourClassInTheSpecFlowProject).Assembly).SingleInstance();

or by registering all classes marked with the [Binding] attribute:

builder.RegisterTypes(typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))).ToArray()).SingleInstance();

A typical dependency builder method probably looks like this:

[ScenarioDependencies]
public static ContainerBuilder CreateContainerBuilder()
{
  // create container with the runtime dependencies
  var builder = Dependencies.CreateContainerBuilder();

  //TODO: add customizations, stubs required for testing

  builder.RegisterTypes(typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))).ToArray()).SingleInstance();
  
  return builder;
}

Release History

v1.2.0

  • Support SpecFlow v3.0 (thx to @jsiegmund)

v1.1.0

  • Support SpecFlow v2.2.1 (thx to Zac Charles, @einsteine89)
  • Allow the container to resolve ScenarioContext, FeatureContext, TestThreadContext, IObjectContainer (by @djmnz)

v1.0.2

  • Reduced the minimum Autofac version to 3.5.2 to target broader audience (PR#1 by @BlackstarSolar)

v1.0.1

  • Fix missing assembly from NuGet package (build order issue)

v1.0.0

specflow.autofac's People

Contributors

gasparnagy avatar sabotageandi avatar djmnz avatar einsteine89 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.