1

Windows Phone 8 アプリケーションに WPToolkitTestFx 単体テスト フレームワークを使用しています。Assert.Fail()またはを実行しているときに以下のエラーが発生しますAssert.IsFalse(true)

タイプ 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' の初回例外が Microsoft.VisualStudio.QualityTools.UnitTesting.Phone.DLL で発生しました

上記のエラーの解決策。

ここにソースコード

    [TestMethod]
    [Asynchronous]
    [Description("Test2: Sample asynchronous test")]
    public void Test2()
    {
        // this test executes asynchronously
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            // ... and then fails

            Assert.IsFalse(true);

            EnqueueTestComplete();
        });
    }

ありがとう、ラグー

4

2 に答える 2

0

http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/20/windows-phone-toolkit-overview.aspxのサンプル コードに従うと、同様のことがわかります。

例外が発生するのは正常です。以下を参照してください。

A first chance exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTesting.Phone.DLL

また、デバッガーがデバイス/エミュレーターに接続されている場合、デバッガーは中断されるため、テストの失敗がどこにあったかを見つけることができます。

    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (Debugger.IsAttached)
        {
            // An unhandled exception has occurred; break into the debugger
            Debugger.Break(); // <- !!! application will stop in debugger here !!!
        }
    }

ただし、プロジェクトを続行する (F5 キーを押す) か、デバッガーで実行していない場合は、アプリケーションが引き続き実行され、終了しないことがわかります。

これにより、テスト結果を確認できます。

于 2013-03-21T13:13:43.437 に答える
-1

質問、アサーションに失敗するのはテストの通常の部分ですか?その場合、そのような例外が発生することを期待するようにフレームワークに指示する必要があります

[TestMethod, Asynchronous]
[Description("Test2: Sample asynchronous test")]
[ExpectedException(typeof(AssertFailedException))]
public void Test2()
{
    // this test executes asynchronously
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        // ... and then fails

        Assert.IsFalse(true);

        //TestComplete();
    });
}

EnqueueDelay(TimeSpan), EnqueueCallback(), EnqueueTestComplete()また、メソッドを非同期としてマークしていることに気付きましたが、メソッド関数を非同期にする非同期呼び出しメソッドを使用していません。

于 2013-03-08T17:44:22.750 に答える