0

データが正しい型に逆シリアル化されているかどうかをテストするために、Windows Phone で単体テストを作成する必要があります。これは私がこれまで行ってきたことです。

[TestMethod]
    [Asynchronous]
    public void SimpleTest()
    {
        await pots = help.potholes();

「pots」は待機できないというエラーが表示されます。Pots は、Web サービスへの非同期呼び出しを行っている potholes 関数からの結果を受け入れるリストです。

これは、Restsharp を使用して呼び出しを行うメソッドです。

public void GetAllPotholes(Action<IRestResponse<List<Pothole>>> callback)
    {

        var request = new RestRequest(Configuration.GET_POTHOLE_ALL,Method.GET);
        request.AddHeader("Accept", "application/json");
        _client.ExecuteAsync(request, callback);

    }

ポットを待機可能にするにはどうすればよいですか? Windows Phone で残りのサービスをテストする正しい方法は何ですか?

Windows Phone Toolkit テスト フレームワークを使用しています

これは私がフォローしているチュートリアルです。 非同期テスト

4

3 に答える 3

1

「非同期」という用語は、現在 .net でオーバーロードされています。

あなたが参照している記事はawaitable、コールバックを介して非同期であるメソッドではなく、メソッドを参照しています。

これをテストする方法の大まかなアイデアを次に示します。

[TestMethod]        
[Asynchronous]
public void SimpleTest()
{
    // set up your system under test as appropriate - this is just a guess
    var help = new HelpObject();

    help.GetAllPotholes(
        response =>
        {
            // Do your asserts here. e.g.
            Assert.IsTrue(response.Count == 1);

            // Finally call this to tell the test framework that the test is now complete
            EnqueueTestComplete();
        });
}
于 2013-03-07T15:42:55.823 に答える
1

as matt expresses the term Asynchronous is now being used in multiple contexts, in the case of test methods on Windows Phone, as you can see in your code piece is not a keyword, but an attributed that has the goal of releasing the working thread to allow other processes to run and for your test method to wait for any changes that could happen in the UI or from a service request.

You can do something like this to make your test to wait.

[TestClass]
public class ModuleTests : WorkItemTest
{
    [TestMethod, Asynchronous]
    public void SimpleTest()
    {
        var pots;
        EnqueueDelay(TimeSpan.FromSeconds(.2)); // To pause the test execution for a moment.
        EnqueueCallback(() => pots = help.potholes());
        // Enqueue other functionality and your Assert logic
        EnqueueTestComplete();
    }
}
于 2013-03-08T17:33:28.633 に答える
0

async .. await を間違った方法で使用しています

これを試して

public async void SimpleTest()
{
    pots = await help.potholes();
    ....
}
于 2013-03-07T07:58:09.213 に答える