我正在运行编码的 ui 自动化并定义了一个方法属性,称为[ExternalDataSource()]
读取文档(csv、xml ...)并将数据解析到一些字典中。我将它复制在这里,以便您更好地了解:
[System.AttributeUsage(System.AttributeTargets.Method)]
public class ExternalDataSource : System.Attribute
{
public ExternalDataSource(string filename)
{
DirectoryInfo di = new DirectoryInfo(Assembly.GetExecutingAssembly().Location);
string file = Path.Combine(Path.GetDirectoryName(di.FullName), filename);
try
{
code
}
catch (Exception)
{
throw new UITestException("Cannot load data source document");
}
}
}
在其中,我尝试访问Assembly.GetExecutingAssembly().Location
以获取复制到 TestResult/Out 文件夹的文件。我将此属性仅分配给整个应用程序中的一个 TestMethod() ,在调试时,我发现应用程序两次进入该属性的 c'tor。两次位置都不一样。一旦它来自 bin/Debug 文件夹,另一次来自 TestResults/Out 文件夹。两个问题:
- 如果我在应用程序中只调用一次,为什么调试器会两次输入该属性?
- 为什么同一个程序集的位置会发生变化?