👨‍💻
Dokumentasi Golang (PT Phincon)
  • 🚀Dokumentasi Bootcamp (PT Phincon)
  • Command di Golang
  • Static Type di Golang
  • Variable and Constant
    • Variable daI Constant
    • Deklarasi Variabel
    • Iota (Auto Increment)
    • Blank Identifier (Variable Underscore)
    • Access Modifier (Public or Private)
  • Tipe Data Primitif
    • Integer dan Unsigned Integer
    • Float dan Complex
    • String
    • Boolean
  • Tipe Data Aggregate
    • Array
    • Struct
  • Tipe Data Reference
    • Slice
    • Map
    • Function in Golang
      • Function
      • Function vs Method
      • Function vs Procedure
      • Private vs Public Function
      • Function Init dan Main
      • Function dengan Return Multiple Value
      • Variadic Function
      • Function sebagai Parameter
      • Anonymous Function
      • Input Function dari CLI
      • Exercise (Function)
  • Default Value setiap Tipe Data
  • Type Declaration di Golang
    • Type Declaration
    • Type Declaration Built-In di Golang
  • Kebab Case, Camel Case, Snake Case & Pascal Case di Golang
  • Konversi Tipe Data
  • If-Else dan Switch
    • If Else
    • Switch
    • Exercise
  • Looping
    • Looping For
    • Looping for range
    • Infinite Looping
    • Penerapan Looping pada Sorting
  • Operator di Golang
    • Arithmetic Operator
    • Assignment Operator
    • Relational Operator
    • Logic Operator
  • Interface
  • Interface Kosong atau Any
  • Nil
  • Pointer
    • Pass By Value dan Pass By Reference
    • Pointer (Pass By Reference)
    • Operator Address (& dan *)
    • Default Value Pointer
    • Tricky Case
    • Pointer pada Parameter di Function
    • Pointer pada Method
  • Package
    • Fmt
    • Rand
    • Os
    • Strings
      • To Lower
      • Contains
      • Split
      • Trim
      • Atoi
      • Itoa
      • EqualFold
    • Random Generator
    • Time
      • Get Current Time By Location
      • Time Sleep
      • Time Since
      • Timer & After
      • AfterFunc
      • Ticker & Tick
  • Go dan JSON
    • JSON vs XML
    • Unmarshal vs Marshal
    • Marshal (Go Object -> JSON)
    • Unmarshal (JSON -> Go Object)
    • Streaming Decoder & Encoder
    • Tag
    • JSON Go Return Byte
  • Go dan CSV
    • Insert Data ke File CSV
    • Insert 1.000.000 Data ke File CSV
  • Goroutine
    • Concurrency vs Parrarel
    • Go Routine Sederhana
    • Go Routine vs Synchronous
    • Wait Group
    • Defer
    • Channel
    • Buffered Channel
    • Select Channel
    • Deadlock - All goroutines are asleep
    • Race Condition
    • Mutex (Mutual Exclusion)
    • RW Mutex vs Mutex
    • Once
    • Pool
    • Atomic
    • Go Max Procs
    • Exit
    • Exercise 1 : Go Routine + Context + Channel
    • Exercise 2 : Worker (Go Routine + Channel + Context)
    • Exercise 3 : Random Worker (Go Routine + Channel + Context)
    • Exercise : Implementasi Goroutine dan Channel pada File CSV
  • Go Context
    • Pengenalan Context
    • Context Background & TODO
    • Context With Value
    • Context WithDeadline dan Context WithTimeout
    • Context WithCancel dan Context Done
  • Pengenalan HTTP
  • Go Native HTTP
    • HTTP Server
    • HTTP Server Multi Handler
    • HTTP Server dengan Serve Mux
    • HTTP Response Writer
    • HTTP Test
    • Routing
    • Konsep Middleware
    • Middleware
    • Get Query Parameter
    • Get Path Parameter
    • Request JSON
    • Request Form
    • Get dan Set Header
    • Get dan Set Cookie
    • Redirect
    • Serve File
    • Upload File
    • Download File
    • Hit Endpoint dengan Curl di Terminal
  • Go Gin Framework
    • HTTP Server
    • Router
    • Middleware
    • Get Query Parameter
    • Get Path Parameter
    • Request JSON
    • Request Form
    • Get dan Set Header
    • Get dan Set Cookie
    • Redirect
    • Serve File
    • Upload File
    • Download File
  • Golang dan Database
    • Instalasi MySQL dengan Docker Desktop
    • Instalasi PostgreSQL dengan Docker
    • Basic SQL
    • SQL Join
    • SQL Relation
    • Golang Database Driver
    • Golang dan SQL
  • Go Unit Test
    • Method di Package Testing
    • Package Assert & Require
    • Running Sub Test
    • Table Test
    • Generate Coverage Unit Testing dalam Bentuk HTML
  • Sonar Qube dan Sonar Scanner
  • Logging
  • Golang dan Redis
  • Golang dan RabbitMQ
    • Instalasi RabbitMQ dengan Docker
    • Instalasi Package RabbitMQ di Golang
    • Publisher dan Consumer
    • Publisher dan Multi Consumer
    • Setting RabbitMQ (Durable, Auto Delete dan Ack)
  • Git Command
  • Git Clone dengan SSH
  • Anotasi dan Package di Java Spring Boot
Powered by GitBook
On this page
  • Installasi Sonar Scanner
  • Installasi Sonar Qube dengan Docker
  • Menjalankan Sonar Qube Image
  • Membuat Project Baru di Sonar Qube

Sonar Qube dan Sonar Scanner

PreviousGenerate Coverage Unit Testing dalam Bentuk HTMLNextLogging

Last updated 1 year ago

Sonar qube merupakan software untuk memeriksa coverage dari unit testing, bug dan duplikasi code dari suatu aplikasi (Golang/Java/dsb). Untuk bisa pass di Sonar Quba coverage unit testing perlu di atas 80 % dan duplikasi harus dibawah 8%.

Installasi Sonar Scanner

Sonar scanner digunakan untuk bisa menjalankan token yang diperoleh dari sonar qube di terminal bash (git bash/etc) untuk Windows OS. Cara instalasinya yaitu:

  1. Download file sonar scanner ZIP pada link berikut

  2. Ekstrak file ZIP tersebut dan letakkan pada suatu folder.

  3. Tambahkan file tersebut pada path di system variabel di system environment variabel. Untuk Windows OS dapat dengan mengikuti cara berikut.

  1. Cek di terminal dengan command berikut untuk memastikan sonar-scanner sudah terinstall.

sonar-scanner.bat -h

Installasi Sonar Qube dengan Docker

Instalasi sonar qube di docker dekstop dapat dilakukan dengan menjalankan command berikut di CMD/bash/powershell. Pastikan sebelum command tersebut dijalankan, docker sudah berjalan.

docker pull sonarqube

Jika menggunakan docker dektop, bisa langsung search sonar qube. Setelah itu klik pull, setelah proses instalasi selesai, sonar qube akan otomatis ada di tab images docker dekstop.

Menjalankan Sonar Qube Image

Klik tombol run di sebelah kanan images.

Klik drop down optional settings dan set sonarqube dengan alamat port yaitu 9000. Selanjutnya klik run dan cek tab containers. Tunggu beberapa saat sampai sonar qube benar-benar sudah berjalan.

Setelah itu, cek localhost:9000 maka akan muncul tampilan berikut. Masukkan username dan password. Untuk pertama kali login user dan password-nya sama yaitu 'admin'. Selanjutnya klik log in.

Membuat Project Baru di Sonar Qube

  1. Untuk membuat project baru klik create project secara manual.

  1. Pilih locally, untuk memiliki aplikasi di local computer yang ingin di cek coverage test-nya.

  1. Ikuti langkah 1 dan 2 pada gambar berikut, pastikan pilih sesuai bahasa pemrograman dan OS yang digunakan. Setelah itu salin token yang diperoleh.

  1. Buat sonnar-project.properties di dalam folder aplikasi Golang. File sonar-project.properties dapat seperti contoh berikut. Nama sonar.projectKey dan sonar.projectName harus sesuai dengan yang diisi di langkah 3.

sonar.projectKey=Sales-Go
sonar.projectName=Sales-Go

sonar.projectVersion=1.0
# source of program
sonar.sources=.
# source of program that will not be scanned by sonnar scanner
sonar.exclusions=**/helper/*,**/docs/**, **/mocks/**
sonar.ts.tslint.configPath=tslint.json
sonar.typescript.lcov.reportPaths=coverage/lcov.info

# testing needs config
sonar.test.inclusions=**/*_test.go
sonar.test.exclusions=**main.go, **/helper/*,**/docs/**, **/mocks/**
sonar.go.coverage.reportPaths=reports/result.out
  1. Jalankan token yang diperoleh pada langkah 3 di folder aplikasi golang yang ingin di cek coverage test-nya.

  1. Setelah command dari sonnar qube telah selesai dijalankan, tab overview di sonar qube akan otomatis berubah seperti di bawah ini.

  1. Scroll ke bawah dan klik bagian angka di samping tanda %, maka akan diarahkan ke hamalan measurement coverage unit test masing-masing file.

Reference:

https://docs.sonarqube.org/latest/analyzing-source-code/scanners/sonarscanner/
LogoSonarQube SonarScanner SetupMedium
Logosonarqube - Official Image | Docker Hub
LogoSonarScanner