How to sonar testcoverage¶
Go¶
add
- run: go mod download
- run: go generate
- name: Unit Tests with Coverage
run: go test -coverprofile=coverage.out ./...
tosonarqube-build.yml
Spring Boot¶
add
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=chickenshock-backend -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xmltosonarqube-build.ymladd
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
topom.xmlto test database add
# Service containers to run with runner-job
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: [DB_PW_HERE]
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
between runs-on: self-hosted and steps to sonarqube-build.yml
Vue¶
add
- run: npm ci
- name: Unit Tests with Coverage
run: npm run test:unit -- --coverage --testResultsProcessor=jest-sonar-reporter
tosonarqube-build.ymlcreate
jest.config.jsin top directoryadd
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
};
tojest.config.jsexecute
vue add unit-jesttype
yexecute
npm install jest jest-sonar-reporter ts-jest @vue/cli-service @vue/cli-plugin-typescript @types/jest --save-devfile folder
/tests/unit/example.spec.tsadd
describe('Example', () => {
test('true is true', () => {
expect(true).toBeTruthy();
});
});
to/tests/unit/example.spec.ts