code覆盖异步方法 [英] Code coverage for async methods

查看:130
本文介绍了code覆盖异步方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我分析code覆盖在Visual Studio 2012年,任何在异步方法的await线都显示为未覆盖,即使他们显然是执行,因为我的测试都通过。在code覆盖报告说,覆盖的方法是的MoveNext ,这是不是在我的code present(也许这是编译器生成的)。

When I analyse code coverage in Visual Studio 2012, any of the await lines in async methods are showing as not covered even though they are obviously executing since my tests are passing. The code coverage report says that the uncovered method is MoveNext, which is not present in my code (perhaps it's compiler-generated).

有没有办法来解决code覆盖异步方法报告?

Is there a way to fix code coverage reporting for async methods?

注意

我只是跑覆盖使用NCover,并覆盖号码来拨打使用的工具很多更有意义。至于现在解决方法,我会切换到这一点。

I just ran coverage using NCover, and the coverage numbers make a lot more sense using that tool. As a workaround for now, I'll be switching to that.

推荐答案

这可以最常见的,如果它等待完成之前你等待操作发生。

This can happen most commonly if the operation you're awaiting is completed before it's awaited.

我建议你至少测试同步和异步成功的情况下,但它也是测试同步和异步错误和取消是一个好主意。

I recommend you test at least synchronous and asynchronous success situations, but it's also a good idea to test synchronous and asynchronous errors and cancellations.

这篇关于code覆盖异步方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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