我已经为Visual Studio实现了一个自定义测试类型。自定义测试类型从dll中读取其测试元素。我的ITip实现非常有效。测试元素被加载并显示在test View工具窗口中。
当我选择测试元素并运行它们时,它们以未执行状态结束。在调试此问题时,我发现从QTAgent32.exe抛出FileNotFoundException。它告诉我它找不到定义测试用例的dll。此外,它在我的TestAdapter之前失败。Initialize方法被调用。我将测试dll复制到Visual studio的PrivateAssemblies目录中。当我这样做时,我的测试元素通过了。我还可以调试自定义测试适配器中的代码。因此,所有这一切的含义是QTAgent32.exe无法在其原始目录中找到我的测试dll。
我的问题是我应该怎么做才能使QTAgent32在原始目录中找到我的测试dll ?为了完成,我添加了Tip Load方法代码:
public override ICollection Load(string location, ProjectData projectData, IWarningHandler warningHandler)
{
Trace.WriteLine("Started RegexTestTip Load.");
if (string.IsNullOrEmpty(location))
{
throw new ArgumentException("File location was not specified!", "location");
}
var fileInfo = new FileInfo(location);
if (!fileInfo.Exists)
{
throw new ErrorReadingStorageException(
string.Format("Could not find a file on the specified location: {0}", location));
}
var result = new List<ITestElement>();
var extension = fileInfo.Extension.ToLower();
if (extension != ".dll")
{
return result;
}
Assembly testAssembly = Assembly.LoadFrom(location);
var testClasses = testAssembly.GetTypes().
Where(t => Attribute.IsDefined(t, typeof(RegexTestClassAttribute)));
foreach (Type testClass in testClasses)
{
PropertyInfo property = testClass.GetProperties().
SingleOrDefault(p => Attribute.IsDefined(p, typeof(TestedRegexAttribute)));
if (property == null || !TestedRegexAttribute.Validate(property))
{
throw new InvalidDataInStorageException("A Regex test must define a Tested Regex property with type Regex");
}
var testCases = testClass.GetProperties().
Where(p => Attribute.IsDefined(p, typeof(RegexTestCaseAttribute)));
foreach (PropertyInfo testCase in testCases)
{
if (!RegexTestCaseAttribute.Validate(testCase))
{
throw new InvalidDataInStorageException("A test case property must return a String value.");
}
var testElement = new RegexTestElement(property, testCase);
testElement.Storage = location;
testElement.Name = testCase.Name;
testElement.Description = "A simple description";
testElement.ProjectData = projectData;
result.Add(testElement);
}
}
Trace.WriteLine("Finished RegexTestTip Load.");
return result;
}
您是否尝试过将dll放在与可执行文件相同的目录中?请原谅这一点的明显,但有时是一些非常简单的事情会伤害我们。但它在GAC中,对吧?