warandpeace
warandpeace

Reputation: 281

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?

Upvotes: 17

Views: 5138

Answers (2)

stefan.schwetschke
stefan.schwetschke

Reputation: 8932

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.

Upvotes: 6

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.

Upvotes: 7

Related Questions