Configuration

SpecFlow's behaviour can be configured extensively using the standard .NET configuration file, App.config, which is automatically added to your project. SpecFlow processes this configuration file in test projects containing feature files.

Unlike other runtime-only tools, SpecFlow also processes the configuration file when generating the unit tests from feature files (which usually happens when you save the feature file). This means that once you have changed the configuration file, you may need to force the unit test to be regenerated if the configuration change affects the generated tests. The Visual Studio integration can detect changes to the configuration file and will prompt you to regenerate the tests. To force the unit tests to be regenerated, right-click on your project in Visual Studio's Solution Explorer and select Regenerate Feature Files from the menu.

Default Configuration

All SpecFlow configuration options have a default setting. In general, configuring your unit test provider is the most important configuration option required, and simple SpecFlow projects may not require any more configuration. The following example shows a simple configuration file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="specFlow"
      type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
  </configSections>
  <specFlow>
    <unitTestProvider name="MsTest" />
  </specFlow>
</configuration>

The following example shows all possible configuration options with their default values (the <configSections> element has been omitted for better readability).

<specFlow>
  <language feature="en-US" tool="{not-specified}" />
  <bindingCulture name="{not-specified}" />
  <unitTestProvider name="NUnit" />
  <generator 
      allowDebugGeneratedFiles="false" 
      allowRowTests="true"
      generateAsyncTests="false"
      path="{not-specified}" />
  <runtime 
      stopAtFirstError="false"
      missingOrPendingStepsOutcome="Inconclusive" />
  <trace 
      traceSuccessfulSteps="true"
      traceTimings="false"
      minTracedDuration="0:0:0.1"
      stepDefinitionSkeletonStyle="RegexAttribute" />
  <stepAssemblies>
    <!-- <stepAssembly assembly="{name-of-assembly-containing-bindings}" /> -->
  </stepAssemblies>
  <plugins>
    <!-- <add name="{plugin-name}" /> -->
  </plugins>
</specFlow>

Configuration Elements

<language>

Use this section to define the default language for feature files and other language-related settings. For more details on language settings, see Feature Language.

Attribute Value Description

feature

culture name (“en-US”)

The default language of feature files added to the project. We recommend using specific culture names (e.g.: “en-US”) rather than generic (neutral) cultures (e.g.: “en”).
Default: en-US

tool

empty or culture name

Specifies the language that SpecFlow uses for messages and tracing. Uses the default feature language if empty and that language is supported; otherwise messages are displayed in English. (Note: Only English is currently supported.)
Default: empty

<bindingCulture>

Use this section to define the culture for executing binding methods and converting step arguments. For more details on language settings, see Feature Language.

Attribute Value Description

name

culture name (“en-US”)

Specifies the culture to be used to execute binding methods and convert step arguments. If not specified, the feature language is used.
Default: not specified

<unitTestProvider>

Use this section to specify the unit test framework used by SpecFlow to execute acceptance criteria. You can either use one of the built-in unit test providers or you can specify the classes that implement custom unit test providers.

Attribute Value Description

name

Name of the unit test provider. See Unit Test Providers.

The name of the built-in unit test provider. If you specify this attribute, you don’t have to specify the other two.
Default: nunit

The following lists all supported providers with their name and generator provider class name:

Name Runtime Provider

nunit

NUnit3TestGeneratorProvider

nunit.2

NUnit2TestGeneratorProvider

mbunit

MbUnitTestGeneratorProvider

mbunit.3

MbUnit3TestGeneratorProvider

xunit

XUnitGeneratorProvider

mstest.2008

MsTestGeneratorProvider

mstest.2010

MsTest2010GeneratorProvider

mstest

MsTest2010GeneratorProvider

mstest.silverlight

MsTestSilverlightGeneratorProvider

mstest.silverlight3

MsTestSilverlightGeneratorProvider

mstest.silverlight4

MsTestSilverlightGeneratorProvider

mstest.windowsphone7

MsTestSilverlightGeneratorProvider

generatorProvider

class name

Obsolete; will be removed in v2.0. Use <plugins> instead.

runtimeProvider

class name

Obsolete; will be removed in v2.0. Use <plugins> instead.

<generator>

Use this section to define unit test generation options.

Attribute Value Description

allowDebugGeneratedFiles

true|false

By default, the debugger is configured to step through the generated code. This helps you debug your feature files and bindings (see Debugging Tests). Disabled this option by setting this attribute to “true”.
Default: false

allowRowTests

true|false

Determines whether "row tests" should be generated for scenario outlines. This setting is ignored if the unit test framework does not support row based testing.
Default: true

generateAsyncTests

true|false

Determines whether the generated tests should support testing asynchronous code. This setting is currently only supported for the Silverlight platform.
Default: false

path

path relative to the project folder

Specifies the custom folder of the SpecFlow generator to be used if it is not in the standard path search list. See Setup SpecFlow Projects for details.
Default: not specified

dependencies

custom dependencies

Specifies the custom dependencies for the SpecFlow generator. See Plugins for details.
Default: not specified

<runtime>

Use this section to specify various test execution options.

Attribute Value Description

detectAmbiguousMatches

true|false

Obsolete, will be removed in v2.0.
Default: true

stopAtFirstError

true|false

Determines whether the execution should stop when encountering the first error, or whether it should attempt to try and match subsequent steps (in order to detect missing steps).
Default: false

missingOrPendingStepsOutcome

Inconclusive| Ignore| Error

Determines how SpecFlow behaves if a step binding is not implemented or pending. See Missing, Pending or Improperly Configured Bindings.
Default: Inconclusive

dependencies

custom dependencies

Specifies custom dependencies for the SpecFlow runtime. See Plugins for details.
Default: not specified

<trace>

Use this section to determine the SpecFlow trace output.

Attribute Value Description

traceSuccessfulSteps

true|false

Determines whether SpecFlow should trace successful step binding executions.
Default: true

traceTimings

true|false

Determines whether SpecFlow should trace execution time of the binding methods (only if the execution time is longer than the minTracedDuration value).
Default: false

minTracedDuration

TimeSpan (0:0:0.1)

Specifies a threshold for tracing the binding execution times.
Default: 0:0:0.1 (100 ms)

stepDefinitionSkeletonStyle

RegexAttribute| MethodNameUnderscores| MethodNamePascalCase| MethodNameRegex

Specifies the default step definition style.
Default: RegexAttribute

Listener

class name

Obsolete, will be removed in v2.0. Use <plugins> instead.

<stepAssemblies>

This section can be used to configure additional assemblies that contain external binding assemblies. The assembly of the SpecFlow project (the project containing the feature files) is automatically included. The binding assemblies must be placed in the output folder (e.g. bin/Debug) of the SpecFlow project, for example by adding a reference to the assembly from the project.

The following example registers an additional binding assembly (MySharedBindings.dll).

<specFlow>
  <stepAssemblies>
    <stepAssembly assembly="MySharedBindings" />
  </stepAssemblies>
</specFlow>

The <stepAssemblies> can contain multiple <stepAssembly> elements (one for each assembly), with the following attributes.

Attribute Value Description

assembly

assembly name

The name of the assembly containing bindings.

<plugins>

This section can be used to configure plugins that contain customisations. See Plugins for more details.

<specFlow>
  <plugins>
    <add name="MyPlugin" />
  </plugins>
</specFlow>

The <plugins> element can contain multiple <add> elements (one for each plugin), with the following attributes:

Attribute Value Description

name

plugin name

The name of the plugin containing the customisations.

path

path relative to the project folder

Specifies the custom folder of the SpecFlow plugin to be used if it is not in the standard path search list. See Plugins for details.
Default: not specified

type

Generator| Runtime| GeneratorAndRuntime

Specifies whether the plugin customises the generator, the runtime or both.
Default: GeneratorAndRuntime