4

I have a Visual Studio solution with multiple projects. I have added corresponding unit test projects in my solution. I am using Cobertura in VSTS to find the code coverage for these projects.

Cobertura publishes separate Cobertura.xml files for all the test projects. 

I would like a way to have a merged code coverage report. I couldn't specify path to multiple summary files in VSTS task for publishing code coverage. Is there a way I could achieve that ?

Additional info - All test cases are run against the same DB

FLICKER
  • 6,439
  • 4
  • 45
  • 75
Kiran
  • 747
  • 2
  • 10
  • 35
  • How come this is related to sql-server?!!! please use tags properly – FLICKER Nov 03 '17 at 18:42
  • Sorry, by mistake i added the sql-server since i am running unit tests against db. It came in suggestions and added it hurriedly. – Kiran Nov 03 '17 at 18:45
  • It's OK, tag suggestions are not always right. Always think what kind of knowledge is required to answer and tag bases on that. having proper tags help you redirect the question to the right persons. – FLICKER Nov 03 '17 at 18:48
  • Sure Flicker. I understood. Thanks for letting me know. – Kiran Nov 03 '17 at 18:54

2 Answers2

3

I couldn't find any direct way to do this. So, I used powershell script in another VSO task to achieve the result. Since the tool generates xml with number of lines in one of the attributes, I have written a script to get the files and read that count and generate new xml with desired Coverage report. It worked since all test projects are for same Database and every project targets different set of stored procedures. It doesn't work if two tests target same stored procedure.

Hope this helps.

* EDIT Adding Powershell Script which I used to merge (First 3 parameters are coverage paths from different unit test projects) *

Param(
[string]$UnitTestPath1,
[string]$UnitTestPath2,
[string]$UnitTestPath3,
[string]$targetCoverageFilePath
 )



[xml]$XmlContent = Get-Content $UnitTestPath1
$coverage = [float]$XmlContent.coverage.'lines-covered'

$XmlContent = Get-Content $UnitTestPath2
$coverage += [float]$XmlContent.coverage.'lines-covered'

$XmlContent = Get-Content $UnitTestPath13
$coverage += [float]$XmlContent.coverage.'lines-covered'
$coverage

$node = $XmlContent.SelectNodes("/coverage");

$node[0].SetAttribute('lines-covered',$coverage) 
$XmlContent.Save($targetCoverageFilePath)

$coverage
Kiran
  • 747
  • 2
  • 10
  • 35
  • Hi, could you share your script please? So it may also help others ;) Thanks. – Skorunka František Oct 22 '18 at 12:43
  • @Kiran, Can you please share the script so that it would help others as well? – SRP Dec 10 '18 at 14:55
  • Hi @SkorunkaFrantišek, SRP I have added the snippet for the same. Sorry for the delay, was involved in some other works and took sometime to find this file. – Kiran Dec 11 '18 at 17:12
0

I think there is a way that we can do this by Enabling the "Code Coverage Enabled" option in VSTS Test Assemblies Task at the time of Build definition without passing the path in code-coverage.

Mani
  • 1,228
  • 3
  • 10
  • 28