Skip to content

[ScenarioDependencies] only called once per feature — breaks per-scenario test isolation #716

Description

Reqnroll Version

2.4.1

Which test runner are you using?

MSTest

Test Runner Version Number

dotnet test, Visual Studio Test Explorer 2022

.NET Implementation

.NET 9.0

Test Execution Method

Visual Studio Test Explorer

Content of reqnroll.json configuration file

{
"$schema": "https://schemas.reqnroll.net/reqnroll-config-latest.json",

"bindingAssemblies": [

]
}

Issue Description

❗️ Problem summary

After migrating from SolidToken.SpecFlow.DependencyInjection to Reqnroll.Microsoft.Extensions.DependencyInjection, we noticed that [ScenarioDependencies(ScopeLevelType.Scenario)] is only invoked once per test run, not per scenario.

This breaks the expected behavior where each scenario should receive a freshly built IServiceProvider.

This issue occurs:

  • In Visual Studio

  • With dotnet test

  • Even when the method is annotated properly with ScopeLevelType.Scenario


⚠️ Impact

  • 💣 Breaks test isolation

  • 🧪 Prevents reseeding in-memory databases (duplicate key errors)

  • 🔧 Makes it impossible to vary mocks or services between scenarios

  • 🐛 Inconsistent with the documentation and intended purpose of ScopeLevelType.Scenario


✅ Expected behavior

[ScenarioDependencies(ScopeLevelType.Scenario)] should be executed once per scenario, with a fresh IServiceProvider or ILifetimeScope built each time.



💬 Additional notes

This behavior works correctly under SolidToken.SpecFlow.DependencyInjection.

Steps to Reproduce

🔄 Steps to reproduce
Create a test project with Reqnroll + Microsoft.Extensions.DependencyInjection plugin

Add [ScenarioDependencies(ScopeLevel = ScopeLevelType.Scenario)] on a method

Add Console.WriteLine(...) inside the method

Create a .feature file with 2+ scenarios

Run with dotnet test or from Test Explorer

💥 Result:
CreateServices() is only called once — the same ServiceProvider is reused across all scenarios.

Link to Repro Project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions