7. Quality Control

7.1. Sonar Qube

docker network create ecosystem
docker network create ecosystem

docker run \
    --name sonarqube \
    --detach \
    --rm \
    --network ecosystem \
    --publish 9000:9000 \
    --volume sonarqube_data:/opt/sonarqube/data \
    --volume sonarqube_logs:/opt/sonarqube/logs \
    --volume sonarqube_extensions:/opt/sonarqube/extensions \
    sonarqube

Note

For SonarQube 8.2+ make sure you're using volumes as shown with the above commands, and not bind mounts. Using bind mounts prevents plugins and languages from populating correctly. https://docs.sonarqube.org/latest/setup/install-server/#header-3

--env SONAR_JDBC_URL=... \
--env SONAR_JDBC_USERNAME=... \
--env SONAR_JDBC_PASSWORD=...

# SONAR_JDBC_URL=jdbc:postgresql://localhost:5432/sonarqube?currentSchema=my_schema

7.2. Sonar Scanner

docker run --rm --network ecosystem -v $(pwd):/usr/src sonarsource/sonar-scanner-cli

7.3. Configuration for Java

Code 7.3. Java
## Sonar Server
sonar.host.url=http://sonarqube:9000/
sonar.login=admin
sonar.password=abcdefghi

## About Project
sonar.projectKey=myjavaproject
sonar.projectName=myjavaproject
sonar.sourceEncoding=UTF-8

## SonarScanner Config
sonar.verbose=false
sonar.log.level=INFO
sonar.showProfiling=false
sonar.projectBaseDir=/usr/src/
sonar.working.directory=/tmp/

## Build Breaker
sonar.buildbreaker.skip=false
sonar.buildbreaker.queryInterval=10000
sonar.buildbreaker.queryMaxAttempts=1000

## Debugging
# sonar.verbose=true
# sonar.log.level=DEBUG
# sonar.showProfiling=true
# sonar.scanner.dumpToFile=/tmp/sonar-project.properties

## Java
sonar.language=java
sonar.java.source=8
sonar.java.binaries=target/classes
sonar.sources=src/main/java
sonar.exclusions=**/migrations/**

7.4. Configuration for Python

Code 7.4. Python
## Sonar Server
sonar.host.url=http://sonarqube:9000/
sonar.login=admin
sonar.password=abcdefghi

## About Project
sonar.projectKey=mypythonproject
sonar.projectName=mypythonproject
sonar.sourceEncoding=UTF-8

## SonarScanner Config
sonar.verbose=false
sonar.log.level=INFO
sonar.showProfiling=false
sonar.projectBaseDir=/usr/src/
sonar.working.directory=/tmp/

## Build Breaker
sonar.buildbreaker.skip=false
sonar.buildbreaker.queryInterval=10000
sonar.buildbreaker.queryMaxAttempts=1000

## Debugging
# sonar.verbose=true
# sonar.log.level=DEBUG
# sonar.showProfiling=true
# sonar.scanner.dumpToFile=/tmp/sonar-project.properties

## Python
sonar.language=py
sonar.sources=.
sonar.inclusions=**/*.py
sonar.exclusions=**/migrations/**,**/*.pyc,**/__pycache__/**

7.5. Automation

Code 7.5. test-functional.sh
#!/bin/sh

cd example-py-doctest/
python3 -m doctest -v doctests/*
Code 7.6. test-integration.sh
#!/bin/sh

pip install -r requirements.txt
cd example-py-pytest/
python3 -m pytest
Code 7.7. test-static.sh
#!/bin/sh

docker run --rm --net ecosystem -v $(pwd):/usr/src sonarsource/sonar-scanner-cli
Code 7.8. test-unit.sh
#!/bin/sh

cd example-py-unittest
python3 -m unittest

7.6. Alternatives

Server side quality monitoring:

Cloud based quality monitoring:

Code Coverage:

Mutation Testing:

Load Testing:

BDD Testing: