Hi Daniel,
Your projects seems to be really interesting, I'm using Pester to generate some Code Coverage reports in Jacoco format but to import it to Sonar we need to reconvert it in the Generic Sonar Format.
Are you planning to add more output formats in the tools soon ?
Best!
Regards
DIB
Doesn't look very difficult to implement (see https://docs.sonarqube.org/latest/analysis/generic-test/)
Will give it a try within the next days.
Thanks so much for your reply, I'll waiting for news!. I was started a parser to convert my current Jacoco output to the generic format of Sonar, but to be completly honest, I'm not sure that we're parsing the output of the file fine.
This is the code that we develop
param (
[string]$in = $( Read-Host "Input pester output file." ),
[string]$out = $( Read-Host "Input output sonarqube generic test path." ),
[switch]$force = $false
)
$xml = [xml](Get-Content $in)
$covered = ($Xml.report.counter | Where-Object Type -eq "INSTRUCTION" | Select-Object -Property covered).covered
$missed = ($Xml.report.counter | Where-Object Type -eq "INSTRUCTION" | Select-Object -Property missed).missed
$outputCoverage = "C:\Users\diego.bellini\Downloads\Code\PowerShell\CodigoSonarqube\src\Get-Pester.ps1"
# Set the File Name
$filePath = $out+"/TestCoverage.GF.xml"
# Create The Document
$XmlWriter = New-Object System.XMl.XmlTextWriter($filePath, $Null)
# Set The Formatting
$xmlWriter.Formatting = "Indented"
$xmlWriter.Indentation = "4"
# Write the XML Decleration
$xmlWriter.WriteStartDocument()
# Write Root Element
$xmlWriter.WriteStartElement("coverage")
$xmlWriter.WriteAttributeString("version", "1")
# Write the Document
$xmlWriter.WriteStartElement("file")
$XmlWriter.WriteAttributeString("path", "$outputCoverage")
$count=0
while ($count -lt $covered) {
$xmlWriter.WriteStartElement("lineToCover")
$XmlWriter.WriteAttributeString("lineNumber", $count+1)
$XmlWriter.WriteAttributeString("covered", "true")
$XmlWriter.WriteEndElement()
$count++
}
$count
# Count total based on last count.
$totalCount=$count+$missed
while ($count -lt $totalCount){
$xmlWriter.WriteStartElement("lineToCover")
$XmlWriter.WriteAttributeString("lineNumber", $count+1)
$XmlWriter.WriteAttributeString("covered", "false")
$XmlWriter.WriteEndElement()
$count++
}
$count
$XmlWriter.WriteEndElement()
# End the XML Document
$xmlWriter.WriteEndDocument;
# Finish The Document
$xmlWriter.Finalize
$xmlWriter.Flush
$xmlWriter.Close()
But if you look at it, we're just parsing the "INSTRUCTION" of the output, and we really don't know if we need to do the same with the other parameters that the Jacoco are giving us like (LINE, METHOD & CLASS) or if we're parsing the file correctly.
So if you can help me with this we will be completely grateful with you.
Thanks so much!
Best
DIB
Please give this new (pre-) release a try:
https://www.nuget.org/packages/ReportGenerator/4.0.6
Use the following arguments:
-reports:mycoveragefile.xml -targetdir:mytargetdir -reporttypes:SonarQube
Please let me know if this works for you.
Before at all, thanks so much for your fast reply again! I'm trying to use the tool but I think that the tool is not working with my report.
This is the Jacoco file that I'm generating with my pester test
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE report PUBLIC "-//JACOCO//DTD Report 1.0//EN" "report.dtd">
<report name="Pester (01/14/2019 10:01:59)">
<sessioninfo id="this" start="1547460118853" dump="1547460119566" />
<counter type="INSTRUCTION" missed="17" covered="12" />
<counter type="LINE" missed="17" covered="10" />
<counter type="METHOD" missed="3" covered="1" />
<counter type="CLASS" missed="3" covered="1" />
</report>
This is the line that I'm executing with your tool
C:\Users\diego.bellini\.nuget\packages\reportgenerator\4.0.6-rc2\tools\net47\ReportGenerator.exe "-reports:C:\Users\diego.bellini\Downloads\Code\PowerShell\CodigoSonarqube\SonarProject\artefacts\TestsCoverage.Jacoco.xml" "-targetdir:C:\Users\diego.bellini\Downloads\Code\PowerShell\CodigoSonarqube\SonarProject\artefacts\" -reporttypes:SonarQube
And this is the file that the tool is generating, that apparently is empty
<?xml version="1.0" encoding="utf-8"?>
<coverage version="1" />
Please let me know if you think that I'm doing something wrong or if you thing that I can give you some more input to understand better what is happening with the tool.
Many thanks!
Regards
DIB
Your command line arguments look fine.
But your JaCoCo file does not contain any coverage information.
The <report> element should contain at least one <package> element.
Here's an example file:
https://github.com/danielpalme/ReportGenerator/blob/master/src/Testprojects/Java/Reports/JaCoCo0.8.3.xml
Perhaps you need to specify the -detailedcodecoverage parameter when executing Pester.
See: https://github.com/pester/Pester/pull/920
Edit:
-detailedcodecoverage seems not to be required any more; see: https://github.com/pester/Pester/pull/1120
So perhaps you are not using the latest version of Pester?!
The version containing https://github.com/pester/Pester/pull/1120 was only released five days ago:
https://github.com/pester/Pester/releases/tag/4.5.0
Thanks so much for your update. I'm trying to parse my Jacoco outputs with the new pester version an apparently your parser are working fine. Let me do some more tests and I will send you a new message with the update soon!