c# - ExcludeFromCodeCoverage 不适用于 asp.net core 3.1 单元测试项目
问题描述
using MyAPI.ShippingAddress.Operations;
using MyAPI.ShippingAddress.Request;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics.CodeAnalysis;
namespace MyAPI
{
public class DependencyServiceFactory
{
[ExcludeFromCodeCoverage]
public void Add(int a, int b)
{
return a + b;
}
}
}
我创建了 asp.net core 3.1 MS 单元测试项目,一切都按预期工作,但 [ExcludeFromCodeCoverage] 不起作用。我需要从代码覆盖结果中删除此方法
有什么建议吗?
解决方案
添加 CodeCoverage.runsettings 文件并使用测试探索对其进行配置。CodeCoverage.runsettings 文件应包含“System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute”
<Attributes>
<Exclude>
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System\.Runtime\.CompilerServices.CompilerGeneratedAttribute$</Attribute>
<Attribute>^System\.CodeDom\.Compiler.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
推荐阅读
- vba - Excel Vba 文本框段落
- javascript - AngularJS - 下拉菜单的问题
- spring-cloud-sleuth - Spring sleuth 中的 WebClient 检测
- sql - 在sql server中获取最后_位置值
- go - 为 Go 中的结构返回 nil
- xml - XSLT 层次结构转换中的重复项
- batch-file - 如何使用批处理删除某些文件夹
- r - cox ph的估计预测精度
- angular - 如何使用服务在 Angular 6 中出现 tslint 错误?
- google-app-engine - Google Endpoints V2 和 Maven 插件版本?