如何在 MSTest 中的 TestMethods 之间共享状态。这些测试将作为有序测试按顺序运行。
private TestContext testContext;
public TestContext TestContext
{
get { return this.testContext; }
set { this.testContext = value;}
}
[TestMethod]
public void Subscribe()
{
bool subscribed = true;
TestContext.Properties.Add("subscribed", subscribed);
Assert.IsTrue(subscribed == true, string.Format("Subscribed...{0}", this.GetHashCode()));
}
[TestMethod]
public void GenerateEvent()
{
bool subscribed = (bool)TestContext.Properties["subscribed"];
Assert.IsTrue(subscribed == true, string.Format("Subscribed...{0}", this.GetHashCode()));
}
提前致谢。