简体   繁体   English

WebService方法的单元测试代码覆盖率,包括异步方法

[英]Unit Testing Code Coverage for WebService Method including async methods

I just need information about code coverage of webservice method that includes Async Methods as well. 我只需要有关网络服务方法的代码覆盖率的信息,其中包括异步方法。

Suppose, I have one method written in WebService, MethodOne(string Value) and I have written TestMethod to check code coverage for this method, 假设我有一个用WebService编写的方法MethodOne(string Value)并且我已经编写了TestMethod来检查该方法的代码覆盖率,

When I run Test and check in code coverage, it showing me something like 当我运行测试并检查代码覆盖率时,它显示出类似以下内容

MethodOne(string) 100% MethodOne(string) 100%

MethodOneAsync(string) 0% MethodOneAsync(string) 0%

MethodOneAsync(string,object) 0% MethodOneAsync(string,object) 0%

so because of Asynchronous methods, I can not verify the actual code coverage of my projects, I want to cover these kind of methods as well in my code coverage. 因此,由于存在异步方法,因此无法验证项目的实际代码覆盖范围,因此我希望在代码覆盖范围内也涵盖这些方法。

I researched on google and read many articles but didn't get a valuable code, I have written following code as well but it doesn't help as well. 我在Google上进行了研究并阅读了许多文章,但没有获得有价值的代码,我也编写了以下代码,但它也没有帮助。

public async void TestMethod1Async()
{
    bool isValue = await System.Threading.Tasks.TaskEx.Run(() => target.IsAccountDisabled(Guid.NewGuid()));
    Assert.IsFalse(isValue);
}

You can write asynchronous unit tests to test asynchronous methods. 您可以编写异步单元测试来测试异步方法。

Asynchronous unit tests must be async Task . 异步单元测试必须是async Task

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM