DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Containers Trend Report: Explore the current state of containers, containerization strategies, and modernizing architecture.

Low-Code Development: Learn the concepts of low code, features + use cases for professional devs, and the low-code implementation process.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • Extending the Salesforce CLI with a Custom Plugin
  • Implementing ROS Communication Patterns
  • Testing Swing Application
  • Emulating the History Command Within a Bash Script

Trending

  • Scaling Micro-Frontends With Orchestrators
  • Data Privacy and Security
  • Micro Frontends for Quarkus Microservices
  • Safeguarding Data Exchange: A Comprehensive Overview of API Gateways and Their Imperative Role in Ensuring Robust Security
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. SonarQube Analysis With Ginkgo on Mac

SonarQube Analysis With Ginkgo on Mac

Ginkgo is the testing framework of choice for many projects developed in Golang. Find out how to setup SonarQube analysis for Golang projects on Mac.

Barzana Panayotova user avatar by
Barzana Panayotova
·
Nov. 02, 21 · Tutorial
Like (3)
Save
Tweet
Share
8.2K Views

Join the DZone community and get the full member experience.

Join For Free

Ginkgo is the testing framework of choice for many projects developed in Golang. Here is an example setup for SonarQube project analysis.

Prerequisites

  • SonarQube server installation: For the purpose of the tutorial I have a docker image running on my machine on http://localhost:9000.
  • SonarQube project: For the purpose of the tutorial I have created a project with project key com.bdpanajotova.golang-sonar-example and name Golang Sonar Example.
  • Golang project for analysis with Ginkgo tests: Here is the example project I use in GitHub.

Here is the documentation for the fast local setup of SonarQube.

My environment is macOS Big Sur 11.3.

Step 1: Setup sonar-scanner

Download the respective version of SonarScanner for your system: sonar-scanner.

Unzip the downloaded file and export it in your PATH.

Shell
 
% unzip sonar-scanner-cli-4.6.2.2472-macosx.zip
Archive:  sonar-scanner-cli-4.6.2.2472-macosx.zip
   creating: sonar-scanner-4.6.2.2472-macosx/
...

% pwd
/Users/barzana.nikolova/Downloads
% export PATH=$PATH:/Users/barzana.nikolova/Downloads/sonar-scanner-4.6.2.2472-macosx/bin
% sonar-scanner -h
INFO:
INFO: usage: sonar-scanner [options]
INFO:
INFO: Options:
INFO:  -D,--define <arg>     Define property
INFO:  -h,--help             Display help information
INFO:  -v,--version          Display version information
INFO:  -X,--debug            Produce execution debug output

Step 2:  Create sonar-scanner.properties File

Create a sonar-scanner.properties file in your project root directory.

Properties files
 
#----- SonarQube Analysis Setup
sonar.host.url=http://localhost:9000
sonar.projectKey=com.bdpanajotova.golang-sonar-example
sonar.projectName=Golang Sonar Example
sonar.login=b58b1848e45247651387fe23dd580e464e67be49 
# Generated token in SonarQube - http://localhost:9000/account/security/

sonar.sources=.
sonar.exclusions=**/*_test.go

sonar.tests=.
sonar.test.inclusions=**/*_test.go

sonar.go.coverage.reportPaths=.coverage/coverage.out

This configuration expects a single coverage report in folder .coverage/coverage.out.

Step 3: Generate Coverage Report 

From the root project directory, execute the following to generate a coverage report file:

Shell
 
% ginkgo -cover -coverprofile=coverage.out -outputdir=.coverage ./...                
Running Suite: Animal Suite
===========================
Random Seed: 1634367783
Will run 2 of 2 specs

••
Ran 2 of 2 Specs in 0.000 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS
coverage: 66.7% of statements
path is /Users/barzana.nikolova/GolandProjects/golang-sonar-example/.coverage
All profiles combined

Ginkgo ran 1 suite in 4.455071542s
Test Suite Passed
barzana.nikolova@Krasimirs-MacBook-Pro golang-sonar-example % 

This command combines all the test coverage output in one file that will be used by sonar-scanner when analyzing your project.

Step 4: Run sonar-scanner

To analyze your project, run the following command:

Shell
 
% sonar-scanner -Dproject.settings=sonar-scanner.properties                          
INFO: Scanner configuration file: /Users/barzana.nikolova/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/barzana.nikolova/GolandProjects/golang-sonar-example/sonar-scanner.properties
INFO: SonarScanner 4.6.2.2472
INFO: Java 11.0.11 AdoptOpenJDK (64-bit)
INFO: Mac OS X 11.3 x86_64
...
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=com.bdpanajotova.golang-sonar-example
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AXyH7DsT6By06DIoRBpH
INFO: Analysis total time: 5.955 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 7.804s
INFO: Final Memory: 14M/54M
INFO: ------------------------------------------------------------------------
barzana.nikolova@Krasimirs-MacBook-Pro golang-sonar-example % 

Step 5: See the Project Analysis in SonarQube

Here is the overall status of the project:

Project Analysis in SonarQube

Here is the uploaded code coverage report:

Uploaded code coverage report


I hope it has become clear how to configure simple sonar scans for Golang Ginkgo projects.

I welcome your thoughts and feedback.

Code coverage Golang shell Testing Directory Command (computing) GitHub

Opinions expressed by DZone contributors are their own.

Related

  • Extending the Salesforce CLI with a Custom Plugin
  • Implementing ROS Communication Patterns
  • Testing Swing Application
  • Emulating the History Command Within a Bash Script

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: