我有一个类(codedUI),包含静态属性,用于保存从运行到运行的变量:
[CodedUITest]
public class SomeClass
{
public static string MyStaticProp { get; set; }
[TestMethod]
public void TestMethod1()
{
SomeClass.MyStaticProp = "AHA";
}
[TestMethod]
public void TestMethod2()
{
string x = SomeClass.MyStaticProp;//when TestMethod1 and TestMethod2 are called from an "ordered test", MyStaticProp is reset everytime. The strange thing: it used to work....
}
}
我认为 MyStaticProp 从运行到运行会保持不变(第一次运行,初始值 = null,第二次运行初始值“AHA”)。但显然 MyStaticProp 从运行到运行总是重置为 null 。知道为什么会发生这种情况吗?
编辑:谢谢大家的帮助!我想我将创建一个“DataClass”,它将保存到临时文件夹/从临时文件夹加载。像这样我可以确定什么时候会发生。
我仍然不明白的是,为什么它过去有效,但现在不再有效。