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
