Giter Site home page Giter Site logo

sonar-j3c's Introduction

sonar-j3c

Coverage Complexity Chart - Sonar Plugin

The J3C Sonar Plugin is a visualization technique that is useful to quickly get an idea of how difficult it is to change / maintain your code. It combines the Cyclomatic Complexity and code Coverage from automated tests and reveals if the code contains areas that are dangerous to change.

The Cyclomatic Complexity and Coverage metrics were chosen because they can spot the code that is associated with an increased risk of breaking an existing functionality:

  • excessive code complexity increases probability of introducing defects during maintenance
  • without automated tests we cannot be sure that the changes have not introduced regressions

This plugin is inspired from crap4j project and uses the same heuristic Complexity / Coverage Thresholds in order to interpret and render the results.

Complexity Coverage %
0 – 5 0%
6 – 10 42%
11 – 15 57%
16 – 20 71%
21 – 25 80%
26 – 30 100%
31+ Time to refactor

Coverage Complexity Chart

The J3C Sonar Plugin leverages JaCoCo library to analyze and extract methods coverage and complexity metrics (more details here and here), groups methods by complexity, computes the average coverage and aggregates the results as a bar chart.

The key elements in the chart above are:

  • the green bars represent the average coverage for related complexity
  • the red bars (if is the case) represent the difference between recommended coverage and the actual one
  • the light yellow color is used to show the boundaries between desired and risky coverage areas

By analyzing the chart above we can see that even the total code line coverage reported by JaCoCo is 72%, there are code areas hard and risky to change.

In the chart below is presented another project (a smaller one) with a lower change code risk.

Coverage Complexity Chart

By examining this chart, the red bar immediately draws the attention to the methods having Cyclomatic Complexity equals with 7. Looking closer to the code, we found out 2 methods having this complexity. The first one has 45% and the second has 15% test coverage resulting in an average value equal to 30%. By increasing the test coverage for the second method we can lower the risk of introducing defects when change is requested.

How to build

Clone a copy of the main J3C Sonar Plugin git repository by running:

git clone https://github.com/cezarcoca/sonar-j3c.git

Enter the sonar-j3c directory

cd sonar-j3c

Run the build script:

mvn clean package

Installation

  1. Copy the plugin into the SONARQUBE_HOME/extensions/plugins directory
  2. Restart the SonarQube server (version 4.3+)

Usage

To launch JaCoCo as part of your Maven build and generate the jacoco.exec execution data file, use this command

mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install

To feed SonarQube with code coverage data, use below command

mvn sonar:sonar

For more information about how to configure SonarQube and JaCoCo see this documentation

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.