Trying to Exclude Unit Tests from Code Coverage

2019-08-23 02:46发布

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.

2条回答
SAY GOODBYE
2楼-- · 2019-08-23 03:16

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>
查看更多
forever°为你锁心
3楼-- · 2019-08-23 03:24

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!

查看更多
登录 后发表回答