ScenarioContext.Current线程安全吗?

Sam*_*amo 5 c# bdd concurrency specflow

我觉得它不是.我有三个集成测试,当单独运行时会成功,但是当并行运行时,我得到了System.ArgumentException: An item with the same key has already been added.

我当然希望ScenarioContext.Current总能提到正确的情况,但似乎它变得混乱了.有没有人成功地为这个类增加了线程安全性?或者我是否应该使用另一种方法在步骤文件之间共享值?

小智 3

ScenarioContext.当前来源:

public static ScenarioContext Current
    {
        get
        {
            if (current == null)
            {
                Debug.WriteLine("Accessing NULL ScenarioContext");
            }
            return current;
        }
        internal set { current = value; }
    }
Run Code Online (Sandbox Code Playgroud)

如您所见,它不是线程安全的 https://github.com/techtalk/SpecFlow/blob/master/Runtime/ScenarioContext.cs