试图从代码覆盖率中排除单元测试 [英] Trying to Exclude Unit Tests from Code Coverage

查看:453
本文介绍了试图从代码覆盖率中排除单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从代码覆盖率分析中排除单元测试项目/文件夹,因为这会夸大代码覆盖率.

I am trying to exclude the unit test projects/folders from the code coverage analysis since it is inflating the code coverage percentage.

我每个人都有不同的层/项目和单元测试项目.如下所示.

I have different layers/projects and unit test projects for each of those. As shown below.

Solution
  DataAccess
  Business
  Service
  Model
  Test.DataAccess
  Test.Business
  Test.Service
  Test.Model

如何排除名称/路径中带有"Test.*"的任何文件夹/项目?我想排除那些文件夹中的所有内容.

How do I exclude any folder/project that has "Test.*" in its name/path? I want to exclude everything within those folders.

我已经尝试了以下模式(以及许多其他模式):

I've tried the patterns below (and many others):

**\*Test.*\*
*Test.*\*
Test.*\*
**/*Test.*/*
*Test.*/*
Test.*/*

我无法排除单元测试文件.似乎无法识别目录名称中的通配符.

I cannot get it to exclude the unit test files. It doesn't seem to recognize wildcards within the directory name.

推荐答案

正如@ G.Ann-SonarSourceTeam和@ Isaiah4110所说,更好的解决方案是让sonarQube一起排除测试项目.我不确定为什么在我们的案例中默认情况下不会发生这种情况,但是我们的解决方案是将"SonarQubeTestProject"属性添加到* .csproj文件中.

As @G.Ann-SonarSourceTeam and @Isaiah4110 stated, a better solution was to have sonarQube exclude test projects all together. I'm not sure why this wasn't happening by default in our case but our solution was to add the "SonarQubeTestProject" property to the *.csproj files.

<PropertyGroup>
  <SonarQubeTestProject>true</SonarQubeTestProject>
</PropertyGroup>

这篇关于试图从代码覆盖率中排除单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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