# Exclude tests (not source code) from code coverage

**URL:** <https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445>\
**Category:** SonarQube Cloud\
**Tags:** dotnet6, dotnet, coverage\
**Created:** [January 26, 2023, 12:55pm UTC](https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445 "2023-01-26T12:55:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpw](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@cpw](https://community.sonarsource.com/u/cpw)\
**Post date:** [January 26, 2023, 12:55pm UTC](https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445/1 "2023-01-26T12:55:29Z")

</div>

Hi,  
I am using SonarClound in AzureDevops to run on our c# projects. We have some integration tests we want to exclude from our code coverage. We only want to use the unit test for code coverage. Integration tests and unit test are separated into ther own folders.

We have tried to set the test folder and then exclude this from source by using the following two parameters:  
sonar.tests=Source/NetTransferCapacityService.FunctionApp.Tests/Unit/  
sonar.exclusions= **/NetTransferCapacityService.FunctionApp.Tests/Unit/** /\*

But we keep getting the error below. Any way to solve this or is there a smarter way to exclude tests from code coverage?

```auto
> INFO: Test paths: Source/NetTransferCapacityService.FunctionApp.Tests/Unit
> 
> INFO: Excluded sources: **/build-wrapper-dump.json,** /NetTransferCapacityService.FunctionApp.Tests/Unit/**/*
> 
> INFO: Excluded sources for coverage: **/NetTransferCapacityService.FunctionApp/Startup.cs,** /NetTransferCapacityService.FunctionApp.Persistence/DbContext/Migrations/*, **/NetTransferCapacityService.FunctionApp/Infrastructure/Http/*
> 
> INFO: Excluded sources for duplication: **/NetTransferCapacityService.FunctionApp.Persistence/DbContext/Migrations/*
> 
> INFO: ------------------------------------------------------------------------
> 
> INFO: EXECUTION FAILURE
> 
> INFO: ------------------------------------------------------------------------
> 
> INFO: Total time: 22.704s
> 
> INFO: Final Memory: 21M/74M
> 
> INFO: ------------------------------------------------------------------------
> 
> ##[error]ERROR: Error during SonarScanner execution
> 
> ERROR: Error during SonarScanner execution
> 
> ##[error]ERROR: File Source/NetTransferCapacityService.FunctionApp.Tests/Unit/Application/Extensions/DateOnlyExtensionsTests.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
> 
> ERROR:
> 
> ERROR: File Source/NetTransferCapacityService.FunctionApp.Tests/Unit/Application/Extensions/DateOnlyExtensionsTests.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files
> 
> ERROR:
> 
> ##[error]The SonarScanner did not complete successfully

```

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [January 27, 2023, 5:17pm UTC](https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445/2 "2023-01-27T17:17:34Z")

</div>

Hi,

Welcome to the community!

Could you provide your full analysis log, please? And maybe also all your properties (leaving out sensitive values, of course).

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![cpw](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@cpw](https://community.sonarsource.com/u/cpw)\
**Post date:** [February 15, 2023, 10:05am UTC](https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445/3 "2023-02-15T10:05:44Z")

</div>

We ended up excluding the tracking results from the dotnet test instead.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [February 22, 2023, 10:06am UTC](https://community.sonarsource.com/t/exclude-tests-not-source-code-from-code-coverage/82445/4 "2023-02-22T10:06:06Z")

</div>

Closed on February 22, 2023, 10:06am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
