单元测试浏览器不会显示为城域应用异步单元测试 [英] Unit Test Explorer does not show up Async Unit Tests for metro apps

查看:100
本文介绍了单元测试浏览器不会显示为城域应用异步单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道这是一个已知的问题。我使用VS2012 RC(旗舰版),以及Win8的版本preVIEW。我创建了一个单元测试库(Metro风格应用),并写了单元测试,其中包括异步/等待关键字。然而,当我编译单元测试项目,单元测试资源管理器中不显示我写的测试。如果我排除异步/等待的关键字,那么单元测试Explorer在我刚写的测试显示出来。有没有人用这个遇到过,或者是它只是我吗?

  [识别TestClass]
公共类UnitTest1
{
    [测试方法]
    公共异步无效SomeAsyncTest()
    {
        VAR的结果=等待StorageFile.GetFileFromPathAsync(一些文件路径);
    }
}


解决方案

单元测试方法被异步必须返回任务,而不是无效

这是因为异步无效方法是很难追踪:没有为单元测试库,找出该测试已完成没有简单的方法。 (这很难,但我认为这不是不可能的。你可以通过使用自定义的SynchronizationContext 做到这一点。)

Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8 Release Preview. I have created a Unit Test Library (metro style app), and wrote a Unit Test, which include async/await keywords. However when I compile the Unit Test project, Unit Test Explorer does not show up the Test I wrote. If I exclude the async/await keywords, then the Unit Test Explorer shows up in the Test I just wrote. Has anyone come across with this before, or is it just me?

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public async void SomeAsyncTest()
    {
        var result = await StorageFile.GetFileFromPathAsync("some file path");
    }
}

解决方案

Unit test methods that are async have to return Task, not void.

That's because async void methods are hard to track: there is no easy way for the unit testing library to find out that the test completed. (It's hard, but I think it's not impossible. You could do this by using a custom SynchronizationContext.)

这篇关于单元测试浏览器不会显示为城域应用异步单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆