Trying to Exclude Unit Tests from Code Coverage

牧云@^-^@ 提交于 2019-12-11 17:02:27

问题


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

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.


回答1:


We had a similar issue and I mentioned the file name pattern instead of the folder name to get by. So we had the unit test file names ending with either test.cs or tests.cs. So I added

**/*Tests.cs
**/*Test.cs

and it works like a charm!




回答2:


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>


来源:https://stackoverflow.com/questions/51904214/trying-to-exclude-unit-tests-from-code-coverage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!