Domanda

I am working code coverage generated by MSTEST.EXE (Visula Studio 2010). I have three type of test running on same dll which generates three code coverage file.

  1. moq unit test (run as gated check-in)
  2. Integration unit test (separate job in Jenkins)
  3. GUI unit test (separate job in Jenkins)

I want to merge all three code coverage in file into one, so to generate consolidated report. I tried the below code.

Public Function JoinCoverageFiles(pcolCoverageFiles As List(Of String)) As CoverageInfo
        Dim lobjResultCoverageInfo As CoverageInfo = Nothing
        Console.WriteLine("Joining coverage file(s)...")
        Try
            For Each lstrCoverageFile As String In pcolCoverageFiles

                Dim lobjCurrentCoverageInfo As CoverageInfo = CoverageInfo.CreateFromFile(lstrCoverageFile)

                If lobjResultCoverageInfo Is Nothing Then
                    lobjResultCoverageInfo = lobjCurrentCoverageInfo
                    Continue For
                End If

                Dim lobjJoinedCoverageInfo As CoverageInfo = Nothing

                Try
                    lobjJoinedCoverageInfo = CoverageInfo.Join(lobjResultCoverageInfo, lobjCurrentCoverageInfo)
                Finally
                    lobjCurrentCoverageInfo.Dispose()
                    lobjResultCoverageInfo.Dispose()
                End Try

                lobjResultCoverageInfo = lobjJoinedCoverageInfo
            Next
        Catch generatedExceptionName As Exception
            If lobjResultCoverageInfo IsNot Nothing Then
                lobjResultCoverageInfo.Dispose()
            End If
            Throw
        End Try
        Console.WriteLine("Joining coverage file(s)... Done")
        Return lobjResultCoverageInfo
End Function

With this code I can join the code coverage file, but I want merged result so that I can get to know which code is covered and uncovered in all the three unit test.

È stato utile?

Soluzione

You can get the merged coverage information for all your runs using the CoverageInfo class.

string ccFileMerged = Path.Combine(Path.GetTempFileName + ".coverage");
CoverageInfo.MergeCoverageFiles("A.coverage", "B.coverage", ccFileMerged);
// now you can use the ccFileMerged to get your merged data

However you should note that the merge will group dlls based on some static information eg. dll guid, which is regenerated per build. So as long as you ensure that all the .coverage files were generated with runs consuming the same dlls the merge will be seamless. If these dlls are generated per run, you will end up seeing a dll entry per unique dll in the .coverage file

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top