-
-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SonarQube Support in ReportGenerator #194
Comments
Doesn't look very difficult to implement (see https://docs.sonarqube.org/latest/analysis/generic-test/) |
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 |
Please give this new (pre-) release a try: Use the following arguments: 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 |
Your command line arguments look fine. Here's an example file: |
Perhaps you need to specify the Edit: So perhaps you are not using the latest version of Pester?! |
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! |
@danielpalme was excited to see this support, BUT the https://docs.sonarqube.org/latest/analysis/generic-test/ format needs 2 files one for coverage and 1 for test execution. Is there a way to gen the test execution file too with reportgenerator? |
@drdamour |
@danielpalme hm ok, i'm clearly outta my depth, somehow it works for cobertura files. but my prior any any future question would be uninformed. thx |
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
The text was updated successfully, but these errors were encountered: