I have a Jenkins job that is using the "Invoke standalone Sonar analysis" for a javascript project.
I thought it was working fine with the following parameters:
sonar.sources=src
sonar.language=js
sonar.dynamicAnalysis=reuseReports
sonar.javascript.jstestdriver.coveragefile=target/test-coverage/jscover.lcov
sonar.javascript.lcov.reportPath=target/test-coverage/jscover.lcov
But then I noticed that the numbers that are being reported in Sonar do not match the number in the lcov file.
When I log into to Sonar I see the code coverage number as 30%.
But when I examine the lcov file, I get completely different numbers:
$lcov --summary target/test-coverage/jscover.lcov
...
lines......: 48.1%
functions..: 41.7%
branches...: no data found
And in fact, when I view the jscover.html report file, I see the total coverage at 48%.
Sonar reports it at 30%.
And drilling down into the individual files, Sonar's results do not match the results in the lcov file either.
For instance:
Just by looking at a particular file, /src/js/models/Call.js, lcov says it’s at 97% code coverage.
But Sonar displays this:
49.0% by unit tests Line coverage:97.0% (97/100)Branch coverage:0.0% (0/98)
It’s as if Sonar is using the Branch Coverage AND the Line Coverage Stats to get the final code coverage results at 49.0%.
Do you know what I am doing wrong? Do you know why Sonar is not using the coverage results from the lcov file? Is it because the Branch Coverage has no data?
Thanks for any insight on this.
Code coverage is recomputed by SonarQube. SonarQube just retrieves from the report whether a line is covered or not by unit tests. Example:
DA:10,0 => it means that line 10 is not covered
DA:20,1 => it means that line 20 is covered
DA:30,5 => it means that line 30 is covered
Then SonarQube recomputes the code coverage:
Number of covered lines / (Number of covered lines + Number of uncovered lines)
Related
I have setup Jenkins to run pylint on all python source files and all the log files are generated (apparently correctly) into a sub-directory as follows:
Source\pylint_logs\pylint1.log, pylint2.log, ..., pylint75.log
I have included a --msg-template definition based on the instructions on my Jenkins Configure page: Post-build Actions->Record compiler warnings and static analysis results->Static Analysis Tools. The template is shown as:
msg-template={path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})
An example of one of the log files being generated by Jenkins/pylint is as follows:
************* Module FigureView
myapp\Views\FigureView.py:1: [C0103, ] Module name "FigureView" doesn't conform to snake_case naming style (invalid-name)
myapp\Views\FigureView.py:30: [C0103, FigureView.__init__] Attribute name "ax" doesn't conform to snake_case naming style (invalid-name)
------------------------------------------------------------------
Your code has been rated at 8.57/10 (previous run: 8.57/10, +0.00)
For the PyLint Report File Pattern, I have: Source/pylint_logs/pylint*.log
It appears that PyLint Warnings is parsing the files because the console output looks like this:
[PyLint] Searching for all files in 'D:\Jenkins\workspace\PROJECT' that match the pattern 'Source/pylint_logs/pylint*.log'
[PyLint] -> found 75 files
[PyLint] Successfully parsed file D:\Jenkins\workspace\PROJECT\Source\pylint_logs\pylint1.log
[PyLint] -> found 0 issues (skipped 0 duplicates)
[PyLint] Successfully parsed file D:\Jenkins\workspace\PROJECT\Source\pylint_logs\pylint10.log
[PyLint] -> found 0 issues (skipped 0 duplicates)
This repeats for all 75 files, even though there are plenty of issues in the log files.
What is odd, is that when I was first prototyping the use of Jenkins on this project, I set it up to just run pylint on a single file. I ran across another StackOverflow post that showed a msg-template that allowed me to get it working (unable to get pylint output to populate the violations graph). I even got the graph to show up for the PyLint Warnings Trend. I used the following definition per the post:
msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg}
Note that this format is slightly different from the one recommended by my Jenkins page (shown earlier). Even though this worked for a single file, neither template now seems to work for multiple files, or else there is something other than the template causing the problem. My graph has flat-lined, and I always get 0 issues reported.
I have had trouble finding useful documentation on the Jenkins PyLint Warnings tool. Does anyone have any ideas or pointers to documentation I can research further? Thanks much!
Ensure pass output-format parameter in pylint command. Example:
pylint --exit-zero --output-format=parseable module1 module2 > pylint.report
you have to set the Pylint's option --message-template in .pylintrc as
msg-template={path}: {line}: [{msg_id} ({symbol}), {obj}] {msg}
output-format=text
I'm trying to figure out how to show Coverage in TFS. with .net CORE.
Below is my build definition. I have a "Test .NET Core" task.
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test?tabs=netcore21
From above url, I found this hint:
Run the tests in the project in the current directory and generate a
test results file in the trx format:
dotnet test --logger:trx
And I have test results working.
(Details of Test-Task and the Publish-Test-Results below)
Publish Test Results (task).
With the following arguments
Test Result Format:
VSTest
Test Results Files
**/*.trx
So I can see Test Results :) (below image)
But how do you get Code Coverage working? (above image, red circle...there is a place holder for Coverage)
What I've tried:
There is a "Coverage" task..but doesn't seem right to me. (image below)
How can we get result of summary report parameters (throughput, received & sent bytes) in JMeter script through non gui mode? I have to implement the benchmarking on whole script rather than each thread to mark the status of script pass/fail by comparing the result to the static .csv file which contains the value of parameters .Kindly let me know the approach to opt.
The easiest way is going for JMeterPluginsCMD Command Line Tool, it can generate various tables and charts out of JMeter's .jtl results file.
So you will need to add the following command as the Post Build Step:
JMeterPluginsCMD --generate-csv SummaryReport.csv --input-jtl result.jtl --plugin-type AggregateReport
You can install JMeterPluginsCMD Command Line Tool using JMeter Plugins Manager
Multiple test cases have been written to test a new Chocolatey function using Pester. How do check whether all branches have been covered?
The current version of Pester (3.0) does support code coverage.
Simply use
Invoke-Pester -CodeCoverage *.ps1
to get a full rapport of code coverage (coverage %) and a summary of all the code lines (branches) not executed during testing:
Tests completed in 10.11s
Passed: 66 Failed: 0 Skipped: 0 Pending: 0
Code coverage report:
Covered 99,20 % of 501 analyzed commands in 22 files.
Missed commands:
File Function Line Command
---- -------- ---- -------
Set-ProgressColor.ps1 Set-ProgressColor 19 Write-Verbose "Progress colors are only supported on the PowerShell com...
UPDATE 2:
Thanks to oɔɯǝɹ for pointing out that Pester has now released a version of Pester that supporting code coverage.
UPDATE 1:
As of Pester Version 3.0, it is now possible to get code coverage information, using:
Invoke-Pester -CodeCoverage <path to file>
This is documented in the project wiki page:
https://github.com/pester/Pester/wiki/Code-Coverage
NOTE: In order to use this, you will require PowerShell version 3.0
ORIGINAL ANSWER:
To the best of my knowledge, Pester doesn't currently support code coverage analysis, but it is something that is being worked on.
There is an open issue for this feature here:
https://github.com/pester/Pester/issues/53
You can see it being worked on here:
http://davewyatt.wordpress.com/2014/06/29/code-coverage-analysis-for-pester-feedback-request/
And there is a screenshot of it working here:
https://twitter.com/nohwnd/status/485093995929157632
So basically, hold tight, and there will hopefully be something soon.
In terms of the actual Chocolatey code base, there is quite a good convention being used, namely that for each *.ps1 file, there "should" be a corresponding ".Tests.ps1 file. If this second file doesn't exist, then there are no unit tests for that function.
I've setup teamcity with my sln file and got the unit tests to show up with the CppUnit plugin that teamcity has. And I get test results in the TeamCity UI.
Now I'm trying to get trending reports to show up for my unit tests and code coverage.
As of code coverage, we're using vsinstr.exe and vsperfmon.exe which produces an XML file.
I'm not quite sure as of what steps I should be taking to make the trending reports and code coverage(not as important) to show up.
I've already seen this post, but the answer seems to require editing the build script, which I don't think would work for my case since I'm building through MSBuild and the .sln file, and the tests are being ran through that build.
So basically I'm trying to get the Statistics tab to show up, and I'm not sure where to begin.
Just add simple Powershell step into your build configuration. Something like this:
function TeamCity-SetBuildStatistic([string]$key, [string]$value) {
Write-Output "##teamcity[buildStatisticValue key='$key' value='$value']"
}
$outputFile = 'MetricsResults.xml'
$xml = [xml] (Get-Content $outputFile)
$metrics = $xml.CodeMetricsReport.Targets.Target[0].Modules.Module.Metrics
$metrics.Metric
| foreach { TeamCity-SetBuildStatistic "$($_.Name)" $_.Value.Replace(',', '') }
It uses XML output from FxCop Metrics. You have to update the script for your actual schema.