GithubHelp home page GithubHelp logo

singhalkul / java-quality-checks Goto Github PK

View Code? Open in Web Editor NEW
37.0 2.0 10.0 1.27 MB

License: Apache License 2.0

XSLT 57.13% Java 42.87%
code-quality pmd checkstyle spotbugs findbugs cpd copy-paste

java-quality-checks's Introduction

Java Quality Checks

Code Quality

Tools

Below are some of the tools that make sure that good practices are followed for the following:

  1. Code coverage by unit tests.
  2. Common Coding standard in the team.
  3. Avoid simple mistakes like unused variables, methods, empty catch blocks, eating exceptions instead of throwing etc.
  4. Avoid copy/pasting of code greater than certain number of tokens.

Jacoco

JaCoCo is an open-source toolkit for measuring and reporting Java code coverage.
Gradle configuration for jacoco is located in gradle/jacoco.gradle.

Command:
gradle test integrationTest jacocoTestCoverageVerification

Output: Coverage report

Notice that the service package is excluded as it is considered as integration test in this example. This is just for demo purposes and in real life, unit tests should be written for the service package as well

PMD

PMD is a source code analyzer. It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth.
Gradle configuration for PMD is located in gradle/pmd.gradle. The PMD checks are defined in config/pmd/ruleSet.xml.

Command:
gradle pmdMain

Output: PMD Report

CPD

CPD is Copy/Paste Detector provided by PMD. It helps in finding duplicate code. It is written using Karp-Rabin string matching algorithm.
Gradle configuration for CPD is located in gradle/pmd.gradle.

Command:
gradle cpd

Output:

         > A failure occurred while executing de.aaschmid.gradle.plugins.cpd.internal.worker.CpdAction
            > CPD found duplicate code. See the report at file:///java-quality-checks/build/reports/cpd/cpdCheck.text

Output file: cpdCheck.text

Checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.
Gradle configuration for checkstyle is located in gradle/checkstyle.gradle.
The checkstyle rules for production code are defined in config/checkstyle/checkstyle.xml.
The checkstyle rules for test code are definned in config/checkstyle/checkstyleTest.xml.

Command:
gradle checkStyleMain
gradle checkStyleTest

Output: Checkstyle main

Checkstyle test

SpotBugs

SpotBugs is a program which uses static analysis to look for bugs in Java code. SpotBugs is the spiritual successor of FindBugs, carrying on from the point where it left off with support of its community.
Gradle configuration for spotbugs is located in gradle/spotbugs.gradle.

Command:
gradle spotBugsMain

Practices

Tests

  • Follow the test pyramid when writing tests for the code. This means a lot of unit tests and handful integration tests.
  • Make sure assertions are written for each and every unit test and they are asserting the functionality under test.
  • Integration tests coverage numbers should not be considered when looking at the coverage numbers.

java-quality-checks's People

Contributors

singhalkul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.