We’ve recently introduced another vstest step as we’re migrating our unit tests to a newer structure. This means that in our analysis build we run one vstest task pointing at one location, followed by another pointing at a different location.
# Old tests - task: VSTest@2 displayName: Run Unit Tests inputs: testSelector: 'testAssemblies' testAssemblyVer2: | test\**\*.test*.dll !**\obj\** !test\bin\** codeCoverageEnabled: true platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' runInParallel: true pathtoCustomTestAdapters: packages testFilterCriteria: TestCategory!=L1&TestCategory!=L2&TestCategory!=L3 # New tests - task: VSTest@2 displayName: 'Run L0 Tests' inputs: testAssemblyVer2: '**/*L0.Test.dll' searchFolder: 'test/bin/L0' testRunTitle: 'L0 tests' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' diagnosticsEnabled: true codeCoverageEnabled: true runInParallel: true
When this is run through our SonarCloud definition, it reports our code coverage at 7.8%. Removing the second task reports our code coverage at 14.8%.
Code coverage is enabled for both test tasks, so I would be under the impression that our code coverage should increase, not decrease under these circumstances.