scalac-scoverage-runtime


License

License

Apache-2.0
Categories

Categories

Scala Languages
GroupId

GroupId

org.scoverage
ArtifactId

ArtifactId

scalac-scoverage-runtime_2.12.12
Last Version

Last Version

1.4.5
Release Date

Release Date

Type

Type

jar
Description

Description

scalac-scoverage-runtime
scalac-scoverage-runtime
Project URL

Project URL

http://scoverage.org/
Project Organization

Project Organization

org.scoverage
Source Code Management

Source Code Management

https://github.com/scoverage/scalac-scoverage-plugin

Download scalac-scoverage-runtime_2.12.12

How to add to project

<!-- https://jarcasting.com/artifacts/org.scoverage/scalac-scoverage-runtime_2.12.12/ -->
<dependency>
    <groupId>org.scoverage</groupId>
    <artifactId>scalac-scoverage-runtime_2.12.12</artifactId>
    <version>1.4.5</version>
</dependency>
// https://jarcasting.com/artifacts/org.scoverage/scalac-scoverage-runtime_2.12.12/
implementation 'org.scoverage:scalac-scoverage-runtime_2.12.12:1.4.5'
// https://jarcasting.com/artifacts/org.scoverage/scalac-scoverage-runtime_2.12.12/
implementation ("org.scoverage:scalac-scoverage-runtime_2.12.12:1.4.5")
'org.scoverage:scalac-scoverage-runtime_2.12.12:jar:1.4.5'
<dependency org="org.scoverage" name="scalac-scoverage-runtime_2.12.12" rev="1.4.5">
  <artifact name="scalac-scoverage-runtime_2.12.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.scoverage', module='scalac-scoverage-runtime_2.12.12', version='1.4.5')
)
libraryDependencies += "org.scoverage" % "scalac-scoverage-runtime_2.12.12" % "1.4.5"
[org.scoverage/scalac-scoverage-runtime_2.12.12 "1.4.5"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-compiler jar 2.12.12
org.scala-lang : scala-library jar 2.12.12

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.2.8

Project Modules

There are no modules declared in this project.

scalac-scoverage-plugin

build Gitter Maven Central Maven Central Maven Central Maven Central License

scoverage is a free Apache licensed code coverage tool for Scala that offers statement and branch coverage. scoverage is available for sbt, Maven, and Gradle.

To see scoverage in action check out the samples project which shows you covered and non-covered statements, along with an upload to coveralls.

Screenshot of scoverage report html

Statement Coverage

In traditional code coverage tools, line coverage has been the main metric. This is fine for languages such as Java which are very verbose and very rarely have more than one statement per line, and more usually have one statement spread across multiple lines.

In powerful, expressive languages like Scala, quite often multiple statements, or even branches are included on a single line, eg a very simple example:

val status = if (age < 18) "No beer" else "Beer for you"

If you had a unit test that ran through the value 18 you would get 100% line coverage yet you only have 50% statement coverage.

Let's expand this example out to be multifacted, albeit somewhat contrived:

val status = if (religion == "Pentecostalist") "Beer forbidden" else if (age < 18) "Underage" else "Beer for you"

Now we would get 100% code coverage for passing in the values ("Buddhist", 34).

That's why in scoverage we focus on statement coverage, and don't even include line coverage as a metric. This is a paradigm shift that we hope will take hold.

Branch Coverage

Branch coverage is very useful to ensure all code paths are covered. Scoverage produces branch coverage metrics as a percentage of the total branches. Symbols that are deemed as branch statements are:

  • If / else statements
  • Match statements
  • Partial function cases
  • Try / catch / finally clauses

In this screenshot you can see the coverage HTML report that shows one branch of the if statement was not executed during the test run. In addition two of the cases in the partial function were not executed. Screenshot of scoverage report html

How to use

This project is the base library for instrumenting code via a scalac compiler plugin. To use scoverage in your project you will need to use one of the build plugins:

Scoverage support is available for the following tools:

If you want to write a tool that uses this code coverage library then it is available on maven central. Search for scalac-scoverage-plugin.

Excluding code from coverage stats

You can exclude whole classes or packages by name. Pass a semicolon separated list of regexes to the 'excludedPackages' option.

For example:

-P:scoverage:excludedPackages:.*\.utils\..*;.*\.SomeClass;org\.apache\..*

The regular expressions are matched against the fully qualified class name, and must match the entire string to take effect.

Any matched classes will not be instrumented or included in the coverage report.

You can also mark sections of code with comments like:

// $COVERAGE-OFF$
...
// $COVERAGE-ON$

Any code between two such comments will not be instrumented or included in the coverage report.

Further details are given in the plugin readme's.

Release History

For a full release history please see the releases page.

org.scoverage

scoverage

Versions

Version
1.4.5
1.4.4
1.4.3
1.4.2