Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Sonar-level code coverage equivalent for Scala?

I'm trying to set up simple code coverage reports for a team coding in mixed Scala/Java at approx. a 90/10 ratio and running into some serious roadblocks. I've previously set up & administrated Sonar to great success with a Java-only team, but it doesn't appear to be an option.

Sonar w/Scala plugin is buggy and appears to support Scala-only projects, not mixed ones.

SCCT integrates with our maven build, but fails out with false-negative test failures repeatedly.

Undercover has been my best luck so far; It's integrated with our maven build & generates reports, but they aren't archived or hosted anywhere as they would be with Sonar. There also appears to be no central index to make it simple to navigate the generated reports.

I've read the answers here on StackOverflow, but they largely date back to 2010 and suggest that no decent solution is available. Has this changed?

Is there something obvious I'm missing?

like image 685
warandpeace Avatar asked Sep 12 '12 22:09

warandpeace


People also ask

Does SonarQube work with Scala?

sonar-scala integrates with Scoverage and reports coverage results back to SonarQube. It also reads JUnit-style reports produced by testing frameworks like ScalaTest or Specs2 and turns those into test metrics in SonarQube.

What is code coverage in Scala?

Code Coverage is a metric that measures what percentage of your code has been executed during unit and integration tests. JaCoCo is a great open-source toolkit for code coverage measurements. JaCoCo was originally written for Java and runs on the JVM, but because it's bytecode-based it works for Scala too.

Can Sonar be used for code coverage?

SonarQube and JaCoCo are two tools that we can use together to make it easy to measure code coverage. They also provide an overview of the overall health of the source code by finding code duplications, bugs and other issues in the code. This helps us to know whether our code is production-ready or not.

Which tool is used to analyze the code coverage in SonarQube?

Now, on each build of your project, your coverage tool should perform its analysis and output its results to one or more files (usually one for test coverage and one for test execution). Then, the SonarScanner, as part of its analysis process, will import those files and send the results to SonarQube.


2 Answers

About Sonar side:

  • yes, the Scala Sonar Plugin development is currently stalled. It was initiated by the community, but nobody has offered to take it over yet. If there are some volunteers, we'll be glad to guide and help them.

  • concerning the support of several languages inside a single project, support will be coming in Sonar. I can't give you a roadmap for it, but we're currently thinking about how to add this support in Sonar in the next releases, so this is a short term issue.

like image 50
Fabrice - SonarSource Team Avatar answered Sep 28 '22 03:09

Fabrice - SonarSource Team


You can either use SCCT or JaCoCo.

  • SCCT: It supports Scala up to version 2.10, but development seems to be a stalled for a about 9 months. It supports Scala natively and works with both, Maven and SBT.
  • JaCoCo is under sctive development. It supports any version of Scala, but not natively, but on bytecode level. So you might get some artifacts, e.g. some code gets only partial coveragege, because the generated bytecode has some theoretical code path JaCoCo sees (but which can never be executed from Scala code).

JaCoCo can be a little tricky to set up with Maven and Scala. Here a few tricks:

  1. Use the variant with the agent launcher. Do not use the variant with preprocessing bytecode.
  2. When using JaCoCo with Maven: There is a Maven task (jacoco:prepare-agent) which will produce the correct expression for the agent launcher and stores it into a property. You can then use this property as a command line parameter when running the Java virtual machine.
  3. Parametrize the agent launcher, so that multiple launches (e.g. for running different tests) write to the same log file. Some IDE plugins will have problems with parsing such a file, but the JaCoCo Hudson plugin for example works fine.
like image 20
stefan.schwetschke Avatar answered Sep 28 '22 05:09

stefan.schwetschke