Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with injecting ScenarioContext into Before Hooks with multithreading (MsTest) #1647

Open
9 of 32 tasks
Oliver-S-Zheng opened this issue Jul 3, 2019 · 4 comments
Open
9 of 32 tasks

Comments

@Oliver-S-Zheng
Copy link

SpecFlow Version:

  • 3.0
  • 2.4
  • 2.3
  • 2.2
  • 2.1
  • 2.0
  • 1.9

Used Test Runner

  • SpecFlow+Runner
  • MSTest
  • NUnit
  • Xunit

Version number: 2.4.0

Project Format of the SpecFlow project

  • Classic project format using packages.config
  • Classic project format using <PackageReference> tags
  • Sdk-style project format

.feature.cs files are generated using

  • SpecFlow.Tools.MsBuild.Generation NuGet package
  • SpecFlowSingleFileGenerator custom tool

Visual Studio Version

  • VS 2019
  • VS 2017
  • VS 2015

Enable SpecFlowSingleFileGenerator Custom Tool option in Visual Studio extension settings

  • Enabled
  • Disabled

Are the latest Visual Studio updates installed?

  • Yes
  • No, I use Visual Studio version 15.7.6

.NET Framework:

  • >= .NET 4.5
  • before .NET 4.5
  • .NET Core 2.0
  • .NET Core 2.1
  • .NET Core 2.2
  • .NET Core 3.0

Test Execution Method:

  • Visual Studio Test Explorer
  • TFS/VSTS/Azure DevOps – Task – PLEASE SPECIFY THE NAME OF THE TASK
  • Command line – PLEASE SPECIFY THE FULL COMMAND LINE

<SpecFlow> Section in app.config or content of specflow.json

  <specFlow>
    <stepAssemblies>
      <stepAssembly assembly="[Assembly Filler]" />
    </stepAssemblies>
    <unitTestProvider name="MsTest" />
  </specFlow>

Repro Project

Issue Description

I'm running two different Testcases in parallel with mstest and I'm trying to inject the ScenarioContext into the BeforeScenario, but more often than not the ScenarioContext for one scenario has the ScenarioInfo of another Scenario. For example, when I have 2 scenarios, one called "Test1" and one called "Test2", when I check the ScenarioInfo, in the thread running "Test2", the Title value would be "Test1"

I'm injecting into the constructor with:
public TestCommon(TestcaseContext tc, ScenarioContext sc, FeatureContext fc)
{
this.tcContext = tc;
this.scenarioContext = sc;
}

Steps to Reproduce

  1. Place debug point in constructor that has ScenarioContext injected for object containing BeforeScenario.
  2. Run testcase in debug mode and check the ScenarioContext's ScenarioInfo

Sometimes the first thread to hit this point has the right scenario info, but the next thread always fails with 'An item with the same key has already been added.' before hitting that breakpoint

@SabotageAndi
Copy link
Contributor

How did you configured the parallel execution in MSTesT?

@Oliver-S-Zheng
Copy link
Author

Oliver-S-Zheng commented Jul 3, 2019

Added " parallelTestCount" in testsettings file

@Oliver-S-Zheng
Copy link
Author

Any update on this? Do you need more information?

@SabotageAndi SabotageAndi added the old-version-used User is not the latest major version label Jul 8, 2019
@SabotageAndi
Copy link
Contributor

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants