vstest.console not createing Code Coverage report

Miske, Stephan M 1 Reputation point
2021-08-05T21:40:05.37+00:00

I have an ASP.net application with unit test and I can't seem to get the code coverage
I have checked Code coverage enabled and I have checked Upload test attachments.

$(Build.BinariesDirectory)\test*UnitTests*.dll
!$(Build.BinariesDirectory)\test**testadapter.dll
!$(Build.BinariesDirectory)\test*testcentric**

when I run I see NUnit3TestExecutor discovered 22 of 22 NUnit test cases using Current Discovery mode, Non-Explicit run
Test Run Successful.
2021-08-05T17:41:06.2258424Z Total tests: 22
2021-08-05T17:41:06.2258485Z Passed: 22
2021-08-05T17:41:06.2258555Z Total time: 19.0859 Seconds
when I go to look at the code coverage *_2021-08-05.12_40_46.coverage.trx that was generated.

I only see code coverage for nunit3.testadapter.dll, nothing for the DLL with the 22 cases.

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
331 questions
{count} votes

7 answers

Sort by: Most helpful
  1. Miske, Stephan M 1 Reputation point
    2021-08-06T12:06:52.613+00:00

    @PengGe-MSFT Here is the requested information, also we use the templates within ADO for our pipelines.

    1. VS2019 build tools
    2. from the log

    [command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" @D:\TFSVSOWork_temp\40874cf1-f644-11eb-99f6-9139f2ce0e48.txt
    2021-08-05T23:24:18.3601273Z Microsoft (R) Test Execution Command Line Tool Version 16.8.0
    2021-08-05T23:24:18.3602154Z Copyright (c) Microsoft Corporation. All rights reserved.
    2021-08-05T23:24:18.3602374Z
    2021-08-05T23:24:18.3654269Z vstest.console.exe
    2021-08-05T23:24:18.3654908Z "D:\TFSVSOWork\359\b\test\ABC.UnitTests.dll"
    2021-08-05T23:24:18.3655160Z /EnableCodeCoverage
    2021-08-05T23:24:18.3655342Z /logger:"trx"
    2021-08-05T23:24:18.3655529Z /TestAdapterPath:"D:\TFSVSOWork\359\s"
    2021-08-05T23:24:18.3656168Z -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CodeCoverage.UseVerifiableInstrumentation=False
    2021-08-05T23:24:18.7960562Z Starting test execution, please wait...
    2021-08-05T23:24:20.4977512Z A total of 1 test files matched the specified pattern.
    2021-08-05T23:24:22.3022827Z NUnit Adapter 4.0.0.0: Test execution started
    2021-08-05T23:24:22.3635705Z Running all tests in D:\TFSVSOWork\359\b\test\ABC.UnitTests.dll
    2021-08-05T23:24:37.8190808Z NUnit3TestExecutor discovered 22 of 22 NUnit test cases using Current Discovery mode, Non-Explicit run

    Yammel

    Your build pipeline references the ‘AppName’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

    Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

    Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

    steps:

    • task: VSTest@2
      displayName: 'VsTest - Build Server - $(AppName) - Unit Test '
      inputs:
      testAssemblyVer2: |
      $(Build.BinariesDirectory)\test*UnitTests*.dll
      !$(Build.BinariesDirectory)\test*testadapter.dll
      !$(Build.BinariesDirectory)\test*testcentric**
      vstestLocationMethod: location
      vstestLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow'
      runSettingsFile: '$/X/Y/Z/$(AppName)'
      runInParallel: false
      codeCoverageEnabled: true
      otherConsoleOptions: '-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CodeCoverage.UseVerifiableInstrumentation=False'
      testRunTitle: 'Build Server $(AppName) Unit Test / Functional Test'
      platform: '$(BuildPlatform)'
      configuration: '$(BuildConfiguration)'
      publishRunAttachments: false

  2. Miske, Stephan M 1 Reputation point
    2021-08-09T17:02:30.647+00:00

    Running it this way I see

    Data collector 'Code Coverage' message: Cannot find CodeCoverage.exe..

    but its where others see it:
    D:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\Team Tools\Dynamic Code Coverage Tools
    and
    D:\Program Files (x86)\Microsoft Visual Studio\2019\TestAgent\Team Tools\Dynamic Code Coverage Tools\amd64

    Is it possible for the developers to override this? I am not the developer, they just tell me it works on their machine.

    Starting test execution, please wait...
    A total of 1 test files matched the specified pattern.
    Data collector 'Code Coverage' message: Cannot find CodeCoverage.exe..
    NUnit Adapter 4.0.0.0: Test execution started
    Running all tests in D:\TFSVSOWork\359\b\test\ABC.UnitTests.dll
    NUnit3TestExecutor discovered 22 of 22 NUnit test cases using Current Discovery mode, Non-Explicit run
    Passed A [426 ms]
    Passed B [96 ms]
    Passed C [13 ms]
    Passed D [7 ms]
    Passed E [66 ms]
    Passed F [2 ms]
    Passed G [2 ms]
    Passed H [2 ms]
    Passed I [2 ms]
    Passed J [2 ms]
    Passed K [2 ms]
    Passed L [2 ms]
    Passed M [10 ms]
    Passed N [3 ms]
    Passed O [1 ms]
    Passed P [3 ms]
    Passed Q [3 ms]
    Passed R [2 ms]
    NUnit Adapter 4.0.0.0: Test execution complete
    Passed S [< 1 ms]
    Passed T [2 ms]
    Passed U [2 ms]
    Passed V [1 ms]
    Results File: D:\TestResults\XYZ_2021-08-09_11_37_15.trx

    Test Run Successful.
    Total tests: 22
    Passed: 22
    Total time: 18.3295 Seconds

    0 comments No comments

  3. PengGe-MSFT 3,336 Reputation points
    2021-08-10T03:51:29.317+00:00

    Hi @Miske, Stephan M

    Thank you for reporting it in Microsoft Q&A.

    After my testing and research, I found the following information:

    /Enablecodecoverage is a command of the Enterprise version of Developer Command Prompt for VS 2019. If you run this command in Build Tools, it will generate a coverage file, but when you open this file in Visual Studio, you will find an exception:

    121805-image.png

    The code coverage feature is available only in Visual Studio Enterprise edition. You can refer to this document for more information.

    Sincerely,
    Peng
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  4. Miske, Stephan M 1 Reputation point
    2021-08-11T12:07:45.897+00:00

    I feel like I am missing something, or your not grasping what I am saying. We are using valid Microsoft development environment, we are using ADO on premise build servers, we are using Microsoft provided templates to run vstest. they do not give the option to run from the Developer Command Prompt. My team just built another pipeline for a Core application and it works as expected, something has changed for our Legacy applications that code coverage is no longer supported. There is no reason that you would install a full version of Visual Studio on a build server that no one will ever develop on or even touch the UI, which is the reason for build the build tools.
    122278-capture3.png122279-capture2.png122280-capture1.png


  5. Miske, Stephan M 1 Reputation point
    2021-08-12T12:03:20.783+00:00

    This is run as administrator


    ** Visual Studio 2019 Developer Command Prompt v16.8.4
    ** Copyright (c) 2020 Microsoft Corporation


    C:\Windows\System32>"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "D:\TFSVSOWork\359\b\test\ABC.UnitTests.dll" /EnableCodeCoverage /logger:"trx" /TestAdapterPath:"D:\TFSVSOWork\359\b\test" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.CodeCoverage.UseVerifiableInstrumentation=False /logger:"trx"
    Microsoft (R) Test Execution Command Line Tool Version 16.8.0
    Copyright (c) Microsoft Corporation. All rights reserved.

    Starting test execution, please wait...
    A total of 1 test files matched the specified pattern.
    Data collector 'Code Coverage' message: Cannot find CodeCoverage.exe..
    NUnit Adapter 4.0.0.0: Test execution started
    Running all tests in D:\TFSVSOWork\359\b\test\MutualFundComplianceImport.UnitTests.dll
    NUnit3TestExecutor discovered 22 of 22 NUnit test cases using Current Discovery mode, Non-Explicit run