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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Extending the Salesforce CLI with a Custom Plugin
  • Implementing ROS Communication Patterns
  • Does 100% Code Coverage Mean Tested?
  • 7 Techniques That Supercharged My Claude-Assisted Development

Trending

  • Genkit Flows as senro Steps: Extremely Powerful AI Pipelines in Go
  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes
  • The Permission Was Valid. The Action Was Not Authorized.
  • Why Kotlin or Java Is the Wrong Question For Enterprises

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  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.

By 
Barzana Panayotova
·
Nov. 02, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
9.6K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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
  • Does 100% Code Coverage Mean Tested?
  • 7 Techniques That Supercharged My Claude-Assisted Development

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook