Scala 3, missing lines in coverage report - scala

I'm facing a weird issue while generating coverage report for a Scala 3 project.
Following is an example of how report looks like a method:
because of some reason it is marking statements as uncovered (especially when they are in for comprehension )
NOTE: s3.list returns Try[Vector[S3ObjectSummary]] and my test-case generates both failure and success case.
I'm using sbt-scoverage plugin (v 2.0.0). My scala version is 3.2.2.
Report is generated via sbt clean coverage test coverageReport command.

Related

Running Regression Test Selection (RTS) for Scala (SBT) - Ekstazi/STARTS

Has anyone tried RTS tools like Ekstazi or STARTS to perform Regression test selection (RTS) for scala SBT (not maven) projects where tests are written using ScalaTests?
I tried by adding following library dependencies in build.sbt but it seems like RTS is not performed when I ran unit test cases (using sbt test command):
https://mvnrepository.com/artifact/org.ekstazi/org.ekstazi.core/5.3.0
https://mvnrepository.com/artifact/org.ekstazi/org.ekstazi.scalatest/5.3.0
Can someone please tell me what is the correct way?

How to get Gradle, Scoverage and Sonarqube to work properly?

I have a multi-module Gradle build that compiles Scala code. I would like to scan the code, collect code coverage and feed the results into Sonarqube.
My "Hello, World!" for this question is located here.
I am runnig the following command:
$ ./gradlew clean build reportScoverage aggregateScoverage
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :a:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :a:compileTestScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :b:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :b:compileTestScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :a:compileScoverageScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :a:reportScoverage
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/index.html
[scoverage] Coverage reports completed
> Task :b:compileScoverageScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
> Task :b:reportScoverage
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/index.html
[scoverage] Coverage reports completed
> Task :aggregateScoverage
[info] Found 2 subproject report files [/java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/scoverage.xml,/java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/scoverage.xml]
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/index.html
[scoverage] Coverage reports completed
BUILD SUCCESSFUL in 13s
21 actionable tasks: 21 executed
When I open /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/index.html, I can see:
There are clearly code coverage numbers in there.
So, then I run the sonar-scanner in order to send the information to Sonarqube:
$ sonar-scanner -Dsonar.projectName=multi-module \
-Dsonar.projectKey=multi-module \
-Dsonar.projectVersion=1.0-SNAPSHOT \
-Dsonar.sources=src/main/scala \
-Dsonar.modules=a,b \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.scala.version=2.11 \
-Dsonar.scala.scoverage.reportPath=build/scoverage-aggregate/scoverage.xml \
-Dsonar.host.url=http://localhost:80/
In the example above, I am running it against the default Docker image from https://github.com/mwz/sonar-scala-docker, but I have also tried this with local installations of Sonarqube 6.7.6 with sonar-scala_2.12-6.7.0-assembly.jar and Sonar 7.4 with sonar-scala_2.12-7.3.1-assembly.jar.
In the image below, there are no code coverage numbers (in either version of the above-mentioned Sonarqubes).
I have valid reported code issues though, (as expected).
What am I doing wrong and why aren't there any code coverage numbers? Is this only supported for SBT? Am I not invoking the right Gradle targets? Am I missing parameters?
As you can see here on sonar-scala's instance of Sonarqube, there's clearly a "Coverage" section showing some values (which I am not getting):
Could somebody, please shed some light on this? I've been trying to get this right for a very long time. If it's a bug, or unfinished features, then finding this out would also be helpful. If it's only supported in SBT, then it would be good to know.
Either way, I'd really appreciate the help! Thanks!
To answer my question, two things:
There are now examples in the sonar-scala project for both single and multi-module projects here.
If executing the build under Windows, the code coverage will not work, due to open issues (64 and #65) with sonar-scala.

Maven test coverage for scala

I want to do test coverage on my Scala project, for which I use Maven as a build tool.
So I found this:
https://github.com/scoverage/scoverage-maven-plugin
And I looked here:
http://scoverage.github.io/scoverage-maven-plugin/1.3.0/check-mojo.html
So now to check test coverage, I run this:
mvn test
And then:
mvn scoverage:check
However, this only makes the tests to be run. I get no information about coverage.
Also, I tried:
mvn scoverage:report
But the result is the same.
So how can I use this tool or another to get test coverage info in a Scala/Maven project?
I have only used Scoverage with SBT, but chances are the usage is the same.
mvn scoverage:check will only generate some metadata - XML - and compare the generated coverage values against any coverage minimum you might have set up.
With mvn scoverage:report you will get some formatted reports. More docs here.

Sonar / JaCoCo4sbt / Jenkins

I would like to know whats the easiest way to plug JaCoCo4sbt's data into Sonar,
In Jenkins I have installed Sonar & JaCoCo's plugins. I have also installed JaCoCo's plugin in Sonar.
My sonar-project.properties file contains :
sonar.jacoco.reportPath=target/jacoco/jacoco.exec
And Jenkins's job execute these commands :
sbt jacoco:cover
/opt/sonar-runner/bin/sonar-runner
SBT_OPTS="-Dsbt.log.noformat=true"
sbt clean update compile test doc
For now I don't get any code coverage data into Sonar
Do you want to report code coverage on Scala code using the Scala plugin for Sonar (http://docs.codehaus.org/display/SONAR/Scala+Plugin)?
Unfortunately it does not yet provide a sensor for code coverage.
It's on the roadmap for future versions.
At least jacoco4sbt successfully generates the file jacoco.exec but it is just not picket up by the Scala plugin.
You'll need the following properties:
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=${build.dir}/jacoco.exec
I don't use sbt, but the following is an ANT example:
Add ant plugins dynamically at buildtime?
Check the properties file at the end for all the Sonar related stuff.

Sonar (JaCoCo) gives 0% coverage if my tests are not in a JUnit4 TestSuite

Hi I am using sonar and I love it...
But I have a somewhat strange behavior with my latest proj.
If I put all my tests in a JUnit 4 #TestSuite JaCoCo gives me a coverage of 86,2% ( Groove baby !!! ) when I run mvn sonar:sonar
If I let the tests by themselves I get 0% coverage even with the Unit test success
100,0%
I don't need a TestSuite for this proj any clue about why JaCoCo is doing this?
BTW: I am using Maven 2.2.1 + Sonar 3.4.1 + sonar-maven-plugin 1.0.
You do not need to define a test suite if your tests respect the "Test*.java" & "*Test.java" naming convention.
You can have a look at the following sample application for which tests are analysed by JaCoCo: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/ut/maven/ut-maven-jacoco-runTests