Everyone talks about code quality and code coverages but no one has the perfect solution. The challenges you face as a growing team are plenty and when the client brings to question your quality of work, you have to be able to stand up for yourself. It’s hard to do so without concrete facts. We faced this recently at ParallelScore and were able to rise to the occasion with the help of SonarQube. Here  is a straight forward steps to get you going with SocarQube for your code coverage and quality reporting.

Prerequisites:

  • VSCode
  • Have a test package install and running on your project
  • Run text and include report path in sonar-project.property file.

Step One

https://docs.sonarqube.org/display/SONAR/Get+Started+in+Two+Minutes

Get Started in Two Minutes

  • Unzip – let’s say in “C:\sonarqube” or “/etc/sonarqube”, the SonarQube distribution once it’s downloaded. (https://www.sonarqube.org/downloads/)
  • Start the SonarQube server:

# On Windows, execute: C:\sonarqube\bin\windows-x86-xx\StartSonar.bat

# On other operating system, execute: Ex. (/etc/sonarqube/bin/[OS]/sonar.sh console)

  • Log in to http://localhost:9000 with System Administrator credentials (admin/admin) and follow the tutorial to analyze your first project.

Step Two

Install Sonar Scanner

https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner

  1. Expand the downloaded file into the directory of your choice. We’ll refer to it as <install_directory> in the next steps.
  2. Update the global settings to point to your SonarQube server by editing <install_directory>/conf/sonar-scanner.properties:
  3. #—– Default SonarQube server
    #sonar.host.url=http://localhost:9000
  4. Add the <install_directory>/bin directory to your path.
  5. You can verify your installation by opening a new shell and executing the command sonar-scanner -h (on Windows platform the command is sonar-scanner.bat -h) .

Step 3

Config your IDE by creating a new Sonar-project.properties file. Sample file below. 

# must be unique in a given SonarQube instance

sonar.projectKey={Key from Sonar Install}

# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.

sonar.projectName={Name from Sonar Server}

sonar.projectVersion=1.0

# Encoding of the source code. Default is default system encoding

sonar.sourceEncoding=UTF-8

# exclude some files and folders (typically dependencies)

sonar.exclusions={List of paths to exclude} Ex.( bower_components/**/*, node_modules/**/*, **/*test*/**)

sonar.java.binaries={path to java} Ex. /usr/bin

sonar.javascript.file.suffixes=.js,.jsx

sonar.sources=.

sonar.tests=.

sonar.test.inclusions=**/*test*/**

sonar.javascript.lcov.reportPaths= Ex. coverage/lcov.info