1
votes

I have a solution with 4 projects (2 regular and 2 test projects). I have a build pipeline in TFS 2018 that builds my solution and checks the code coverage. My problem is that only the code coverage from one project is reported. The code coverage from the other project is missing. All tests are run, though.

The Visual Studio Test step looks like this:

enter image description here

The relevant sections of the .runsettings file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
            <ModulePaths>
              <Include>
                <ModulePath>.*\.dll$</ModulePath>
              </Include>
              <Exclude>
                <ModulePath>.*CPPUnitTestFramework.*</ModulePath>
                <ModulePath>.*moq.dll</ModulePath>
                <ModulePath>.*Tests.dll</ModulePath>
              </Exclude>
            </ModulePaths>

        <!-- We recommend you do not change the following values: -->
        <UseVerifiableInstrumentation>False</UseVerifiableInstrumentation>
        <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
        <CollectFromChildProcesses>True</CollectFromChildProcesses>
        <CollectAspDotNet>False</CollectAspDotNet>

      </CodeCoverage>
    </Configuration>
  </DataCollector>
</DataCollectors>

Here is the log output from the test step:

2018-11-19T13:19:41.2308934Z ##[section]Starting: VsTest - netframework
2018-11-19T13:19:41.2412211Z ==============================================================================
2018-11-19T13:19:41.2412390Z Task : Visual Studio Test
2018-11-19T13:19:41.2412658Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test runner. Test frameworks that have a Visual Studio test adapter such as xUnit, NUnit, Chutzpah, etc. can also be run. Tests can be distributed on multiple agents using this task (version 2).
2018-11-19T13:19:41.2412934Z Version : 2.3.28
2018-11-19T13:19:41.2413056Z Author : Microsoft Corporation
2018-11-19T13:19:41.2413412Z Help : More Information
2018-11-19T13:19:41.2413616Z ==============================================================================
2018-11-19T13:19:42.4501863Z Run the tests locally using vstest.console.exe
2018-11-19T13:19:42.4502051Z ========================================================
2018-11-19T13:19:42.4502460Z Test selector : Test assemblies
2018-11-19T13:19:42.4502750Z Test assemblies : * * \release\ * Tests.dll,! * * \obj\ * *
2018-11-19T13:19:42.4503062Z Test filter criteria : null
2018-11-19T13:19:42.4503281Z Search folder : C:\agent_work\1\s
2018-11-19T13:19:42.4503610Z Run settings file : C:\agent_work\1\s\MyProject\CodeCoverage.runsettings
2018-11-19T13:19:42.4503933Z Run in parallel : false
2018-11-19T13:19:42.4504212Z Run in isolation : false
2018-11-19T13:19:42.4505649Z Path to custom adapters : C:\agent_work\1\s\MyProject\Project2Tests\bin\release
2018-11-19T13:19:42.4505955Z Other console options : null
2018-11-19T13:19:42.4506168Z Code coverage enabled : false
2018-11-19T13:19:42.4506699Z Rerun failed tests: false
2018-11-19T13:19:42.8500173Z VisualStudio version selected for test execution : toolsInstaller
2018-11-19T13:19:43.0554534Z ========================================================
2018-11-19T13:19:43.1339450Z [command]C:\agent_work_tool\VsTest\15.9.1-preview-20181023-04\x64\tools\net451\Common7\IDE\Extensions\TestPlatform\vstest.console.exe @C:\WINDOWS\SERVIC~3\NETWOR~1\AppData\Local\Temp\c6857b51-ebfd-11e8-a1f3-554a7ebf3861.txt
2018-11-19T13:19:43.3385913Z Microsoft (R) Testausführungs-Befehlszeilentool Version 15.9.1-preview-20181023-04
2018-11-19T13:19:43.3451743Z Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
2018-11-19T13:19:43.3452021Z
2018-11-19T13:19:43.3612218Z vstest.console.exe
2018-11-19T13:19:43.3612440Z "C:\agent_work\1\s\MyProject\Project1Tests\bin\Release\Project1Tests.dll"
2018-11-19T13:19:43.3612731Z "C:\agent_work\1\s\MyProject\Project2Tests\bin\Release\Project2Tests.dll"
2018-11-19T13:19:43.3612945Z /Settings:"C:\agent_work\1\s\MyProject\CodeCoverage.runsettings"
2018-11-19T13:19:43.3613085Z /logger:"trx"
2018-11-19T13:19:43.3613289Z /TestAdapterPath:"C:\agent_work\1\s\MyProject\Project2Tests\bin\release"
2018-11-19T13:19:43.6746135Z Die Testausführung wird gestartet, bitte warten...
2018-11-19T13:19:44.9662159Z Microsoft (R) Coverage Collection Tool Version 15.0.30319.3000
2018-11-19T13:19:44.9663027Z
2018-11-19T13:19:44.9666782Z
2018-11-19T13:19:44.9674700Z Copyright (c) Microsoft Corporation. All rights reserved.
2018-11-19T13:19:44.9677551Z
2018-11-19T13:19:50.3174860Z Bestanden Test1
... lots of other tests ...
2018-11-19T13:19:53.3609732Z Microsoft (R) Coverage Collection Tool Version 15.0.30319.3000
2018-11-19T13:19:53.3610319Z
2018-11-19T13:19:53.3610430Z
2018-11-19T13:19:53.3610840Z Copyright (c) Microsoft Corporation. All rights reserved.
2018-11-19T13:19:53.3611590Z
2018-11-19T13:19:53.8607813Z Bestanden Test2
... more tests ...
2018-11-19T13:19:53.9355517Z Ergebnisdatei: C:\agent_work\1\s\TestResults\TFS-BUILD09$_TFS-BUILD09_2018-11-19_14_19_50.trx
2018-11-19T13:19:53.9358179Z
2018-11-19T13:19:53.9451115Z Anlagen:
2018-11-19T13:19:53.9470455Z C:\agent_work\1\s\TestResults\332a54cb-163b-4b3b-9bd4-2f5a5be70f4e\TFS-BUILD09$_TFS-BUILD09 2018-11-19 14_19_44.coverage
2018-11-19T13:19:53.9591330Z
2018-11-19T13:19:53.9709295Z Tests gesamt: 128. Bestanden: 128. Fehler: 0. Übersprungen: 0.
2018-11-19T13:19:53.9741454Z Der Testlauf war erfolgreich.
2018-11-19T13:19:53.9781474Z Testausführungszeit: 8,6925 Sekunden
2018-11-19T13:19:54.2519255Z Publishing test results to test run '178'
2018-11-19T13:19:54.2519974Z Test results remaining: 128. Test run id: 178
2018-11-19T13:19:54.3272038Z ##[section]Async Command Start: Publish test results
2018-11-19T13:19:54.6094836Z Published Test Run : https://xxx/_TestManagement/Runs#runId=178&_a=runCharts
2018-11-19T13:19:54.6095328Z ##[section]Async Command End: Publish test results
2018-11-19T13:19:54.6096656Z ##[section]Finishing: VsTest

1
Look at the output of the test step. Are all the tests you're expecting to run being run? Update your question with the logs.Daniel Mann
@Daniel Mann: Yes, all tests are run. I checked the log. I will update my question.gartenriese

1 Answers

1
votes

I finally found the answer.

In the Include section of the .runsettings-file, I had this:

<Include>
    <ModulePath>.*\.dll$</ModulePath>
</Include>

This means that only the .dll-assemblies are being evaluated. To also include the .exe-assemblies, you have to write the following:

<Include>
    <ModulePath>.*\.dll$</ModulePath>
    <ModulePath>.*\.exe$</ModulePath>
</Include>