3

Visual Studio のカスタム テスト タイプを実装しました。カスタム テスト タイプは、そのテスト要素を dll から読み取ります。私の ITip 実装は魔法のように機能しています。テスト要素がロードされ、テスト ビュー ツール ウィンドウに表示されます。

テスト要素を選択して実行すると、未実行ステータスになります。この問題をデバッグしているときに、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;
}
4

1 に答える 1

1

実行可能ファイルと同じディレクトリにdllを入れてみましたか? それが明白であることを許してください。しかし、それはGACにありますよね?

于 2013-06-16T06:23:54.313 に答える