【发布时间】:2011-05-31 11:10:06
【问题描述】:
我有一个类(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”,它将保存到临时文件夹/从中加载。 像这样我可以确定什么时候会发生。
我仍然不明白,为什么它过去有效,但现在不再有效了。
【问题讨论】:
-
@Abdul - 更准确地说,每个
AppDomain一次,这不太一样;每个进程可以有多个AppDomains -
跑来跑去是什么意思?每个 AppDomain 初始化静态变量一次。
标签: c# static properties coded-ui-tests