Skip to content
pdhammond edited this page Sep 16, 2013 · 27 revisions

The behavior of SpecFlow can be extensively configured through .NET configuration files. SpecFlow processes the configuration file of the acceptance test projects (the projects that contain the feature files). The configuration has to be placed in a file called “App.config” (the standard configuration file convention for .NET) and added to the project.

Unlike other runtime-only tools, SpecFlow processes the configuration file also while it generates the unit-tests from the feature files (this happens usually when you save the feature file). This means that after you have changed the configuration file, you might need to force re-generation of the unit test (if the configuration change affects the generated tests). The Visual Studio integration can detect the change of the configuration file and offers re-generation. In Visual Studio you can also force re-generation from the context menu of the project node in the solution explorer.

Default Configuration

In SpecFlow every configuration option has a default setting, so in an extreme case you don’t need to specify any configuration file. Commonly the most important thing to configure is the unit test provider. Therefore simple SpecFlow projects configure only this aspect. The following example shows such a simple configuration.

<?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 config section definition 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-bindgins}" /> -->
  </stepAssemblies>
  <plugins>
    <!-- <add name="{plugin-name}" /> -->
  </plugins>
</specFlow>

Configuration Elements

<language>

This section can be used to define the default language for the feature files and other language-related settings. Read more about the language settings in the Feature Language page.

Attribute Value Description
feature culture name (“en-US”) The default language of the feature files added to the project. It is recommended to use specific culture names (e.g.: “en- US”) and not 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 if supported otherwise the messages are displayed in English. (Currently only English is supported.)
Default: empty

<bindingCulture>

This section can be used to define the culture for executing binding methods and for converting step arguments. Read more about the language settings in the Feature Language page.

Attribute Value Description
name culture name (“en-US”) Specifies a culture to be used to execute binding methods and convert step arguments. If not specified, the feature language is used.
Default: not specified

<unitTestProvider>

This section can be used to specify the unit-test framework SpecFlow uses to execute the acceptance criteria. You can either use one of the built-in unit-test providers or you can specify the classes that implement the 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
generatorProvider class name Obsolete, will be removed in v2.0. Use [[<plugins>|Plugins]] instead.
runtimeProvider class name Obsolete, will be removed in v2.0. Use [[<plugins>|Plugins]] instead.

<generator>

This section can be used to specify various unit-test generation options.

Attribute Value Description
allowDebugGeneratedFiles true|false The debugger is by default configured to step through the generated code. This helps to debug from the feature files directly to the bindings (see Debugging Tests). This feature can be disabled by setting this attribute to “true”.
Default: false
allowRowTests true|false Specifies if "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 Specifies if the generated tests should support testing asynchronous code. This setting is currently supported only 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 SpecFlow generator. See Plugins for details.
Default: not specified

<runtime>

This section can be used to specify various test execution options.

Attribute Value Description
detectAmbiguousMatches true|false Obsolete, will be removed in v2.0.
Default: true
stopAtFirstError true|false Specifies whether the execution should stop at the first error or should continue to try matching the subsequent steps (in order to detect missing steps).
Default: false
missingOrPendingStepsOutcome Inconclusive|
Ignore|
Error
Specifies how SpecFlow should behave if a step binding is not implemented or pending. See Missing, Pending or Improperly Configured Bindings.
Default: Inconclusive
dependencies custom dependencies Specifies the custom dependencies SpecFlow runtime. See Plugins for details.
Default: not specified

<trace>

This section can be used to configure how and what should SpecFlow trace out to the unit test output.

Attribute Value Description
traceSuccessfulSteps true|false Specifies whether SpecFlow should trace successful step binding executions.
Default: true
traceTimings true|false Specifies 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>|Plugins]] instead.

<stepAssemblies>

This section can be used to configure additional assemblies that contain bindings ([[external binding assemblies| Use Bindings from External Assemblies]]). The assembly of the SpecFlow project (the project with the the feature files) is automatically included. The binding assemblies have to 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 too.

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 customizations. See Plugins page for details.

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

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

Attribute Value Description
name plugins name The name of the plugin containing customizations.
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 customizes the generator, the runtime or both.
Default: GeneratorAndRuntime

Clone this wiki locally