![](/img/trans.png)
[英]Unit test for API Controller in ASP.NET Core 3.1 returning a wrong status code
[英]ExcludeFromCodeCoverage not work with asp.net core 3.1 unit test project
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 核心 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.