我知道之前也有人问过这个问题,但是我找不到解决这个问题的方法。
我有一个 Microsoft Azure 事件中心处理器 ProcessorHost
,它正在实现 IEventProcessor
接口(interface)。
它具有方法 IEventProcessor.OpenAsync
、IEventProcessor.CloseAsync
以及此类中的一些其他自定义方法。对于那些自定义方法,我已经使用 MSTest 编写了测试用例并且它们已经通过。
现在我已经用 [ExcludeFromCodeCoverage]
修饰了 OpenAsync
和 CloseAsync
方法,如下所述。
[ExcludeFromCodeCoverage]
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
}
[ExcludeFromCodeCoverage]
Task IEventProcessor.OpenAsync(PartitionContext context)
{
}
我正在使用 Sonar-cube 来测试代码覆盖率。当我运行报告以查看代码覆盖率时,它显示 OpenAsync
方法被覆盖,但即使在使用 [ExcludeFromCodeCoverage]< 装饰后,
。 CloseAsync
方法也没有被覆盖
所以我想知道 CloseAsync 方法是否需要执行其他任何操作才能将其排除在代码覆盖范围之外。
编辑: closeAsync的完整方法
async Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
{
if (reason == CloseReason.Shutdown)
{
await context.CheckpointAsync();
}
}
最佳答案
看看删除 async/await 是否有帮助。
[ExcludeFromCodeCoverage]
Task IEventProcessor.CloseAsync(PartitionContext context, CloseReason reason)
if (reason == CloseReason.Shutdown) {
return context.CheckpointAsync();
}
return Task.CompletedTask;
}
这是两种方法的实现之间唯一明显的区别
关于c# - ExcludeFromCodeCoverage 不适用于 CloseAsync 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51074794/