Coder Social home page Coder Social logo

rolandtritsch / scalac-scoverage-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scoverage/scalac-scoverage-plugin

0.0 2.0 0.0 6.02 MB

Scoverage Scala Code Coverage Core Libs

Home Page: http://scoverage.org

License: Apache License 2.0

Shell 1.01% Scala 98.82% HTML 0.17%

scalac-scoverage-plugin's Introduction

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, Mill, and Gradle.

NOTE: That this repository contains the Scala compiler plugin for Code coverage in Scala 2 and other coverage utilities for generating reports. For Scala 3 code coverage the compiler natively produces code coverage output, but the reporting logic utilities are then shared with the Scala 2 code coverage utilities in this repo.

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 (Color == Red) Stop else Go

If you had a unit test that ran through the Color Red 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 (Color == Red) Stop else if (Sign == Stop) Stop else Go

Now we would get 100% code coverage for passing in the values (Green, SpeedLimit).

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 exclude files from being considered for instrumentation.

-P:scoverage:excludedFiles:.*\/two\/GoodCoverage;.*\/three\/.*

Note: The .scala file extension needs to be omitted from the filename, if one is given.

Note: These two options only work for Scala2. Right now Scala3 does not support a way to exclude packages or files from being instrumented.

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.

scalac-scoverage-plugin's People

Contributors

sksamuel avatar gslowikowski avatar ckipp01 avatar scala-steward avatar richardbradley avatar 0xroch avatar mtkopone avatar radoburansky avatar maiflai avatar kwestor avatar gbasler avatar xuwei-k avatar lustefaniak avatar armanbilge avatar dependabot[bot] avatar lefou avatar rigoford avatar philippus avatar pbatko avatar thepler avatar sullis avatar ruippeixotog avatar takayahilton avatar vincentdehaan avatar joshrosen avatar domizei385 avatar rorygraves avatar luben avatar yshnb avatar viktor-podzigun avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.