0

1つのテストでテスト対象のアプリケーションを起動し、開いたアプリケーションを他のテストで使用したいと思います。これは、アプリケーションの起動にかなりの時間がかかり、テストごとに繰り返すとコストがかかる可能性があるためです。UIマップオブジェクトとともに初期化されるオブジェクトマップに、AUTによる単一のオブジェクトが必要です。

オブジェクトが静的であっても、異なるテスト間でオブジェクトが渡されないため、このメソッドは失敗します。この問題の解決策はありますか?

UIMap

public partial class UIMap
{
    public ApplicationUnderTest _aut { get; set; }

    public void AUT_Open()
    {
        string AUTExecutable = ConfigurationManager.AppSettings["AUTExecutable"];
        _aut = ApplicationUnderTest.Launch(AUTExecutable );
    }
    ...
 }

テスト

private static UIMap map;

[TestMethod]
public void Test01()
{
    ...
    this.UIMap.RecognitionDesigner_Open();
}

[TestMethod]
public void Test02()
{
    //Do something on the UIMap that tries to use the same member variable- _aut 
    //in the UIMap
}
4

3 に答える 3

1

I was able to solve this issue by using _aut.CloseOnPlaybackCleanup = false;. Apparently, the reference to the UIMap object seems to get lost at the end of each test method.

public partial class UIMap
{
    public ApplicationUnderTest _aut { get; set; }

    public void AUT_Open()
    {
         string AUTExecutable = ConfigurationManager.AppSettings["AUTExecutable"];
         _aut = ApplicationUnderTest.Launch(AUTExecutable );
         _aut.CloseOnPlaybackCleanup = false;
    }
    ...
}
于 2013-03-21T08:39:45.027 に答える
0

テストは互いに独立して実行され、UIMap は各テストで再作成されます。ClassInitializeこの属性でマークされたメソッドは、クラス内のすべてのテストの前に一度だけ実行されるため、属性を使用することをお勧めします。テストの実行順序に依存しているため、プロセスが開始されることは絶対に確実です。これは良くありません。

private static TestContext contextSave;

[ClassInitialize]
public static void DoOneTime(TestContext context)
{
    string AUTExecutable = ConfigurationManager.AppSettings["AUTExecutable"];
    _aut = ApplicationUnderTest.Launch(AUTExecutable );
    context.Properties.Add("AUT", _aut);
    contextSave = context;
}

[TestMethod]
public void Test01()
{
   //...
   DoSthmWithAUT(context.Properties["AUT"]);
}

[TestMethod]
public void Test02()
{
    DoOtherWithAUT(context.Properties["AUT"]);
}
[ClassCleanup]
public static void Cleanup()
{
     contextSave = null;
}

一般に、Test01 が Test02 の前にのみ実行されることはわかりません。本当に注文したい場合は、 を使用してOrdered Testsください。

于 2013-03-19T11:31:50.910 に答える