liveBook · Manning

Parameterized execution

As explained in Effective Behavior-Driven Development

A pattern in which automation code uses test parameters to vary execution choices and extend scenario coverage.

When an automated scenario needs to run with different browsers, dependencies, or application settings, parameterized execution makes those choices depend on test configuration. This lets teams vary execution to extend coverage without making every scenario variation a separate scenario. section 20.0 section 20.3

Before varying execution, decide which scenarios should run for each parameter value:

  • Check which scenarios are affected. Rerunning every scenario with different database options, for example, may waste time when only a few use the database. section 20.3
  • Check which scenarios support each value; exclude scenarios that cannot run with a particular service or configuration. section 20.3
  • Use tags to filter reruns when only a subset of scenarios is relevant. If few scenarios both benefit from and support a variation, consider scenario outline examples instead. section 20.3
  • Weigh the coverage benefit against added execution time and infrastructure costs. section 20.3
Listing 20.4 Register stub or real database depending on a test configuration parameter
*** Support/DiConfiguration.cs ***
[Binding]
public class DiConfiguration(
    TestConfigurationProvider testConfigurationProvider)
{
  [BeforeScenario(Order = 0)]
  public void SetupDependencies(IObjectContainer scenarioContainer)
  {
    if (testConfigurationProvider.Database.UseStub)    #A
    {
      scenarioContainer.RegisterTypeAs<StubDatabaseDriver, 
          IDatabaseDriver>();    #B
      scenarioContainer.RegisterTypeAs<StubDataRepository,
          IDataRepository>();    #B
    }
    else
    {
      scenarioContainer.RegisterTypeAs<DatabaseDriver, 
          IDatabaseDriver>();    #C
      scenarioContainer.RegisterTypeAs<DataRepository,
          IDataRepository>();    #C
      ...
    }
  }
}

The dependency registration checks a test configuration setting to choose stub or real database components. section 20.3

How Effective Behavior-Driven Development covers it

How deep it goes
Explains configuration-driven choices, scenario selection, tagging, and trade-offs, with a dependency-registration example.
Examples
Uses browser choice, stub or real dependencies, operating systems, infrastructure, external service versions, and feature toggles.
What you can do after
Configure automation to select behavior from test settings and filter reruns to scenarios that support each value.
How it connects
Connects to the Test Configuration pattern, the Parameterized Scenario pattern, scenario outlines, and tags.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.