How to sonar testcoverage

Go

  1. add
    - run: go mod download
    - run: go generate
    - name: Unit Tests with Coverage
    run: go test -coverprofile=coverage.out ./...
    to sonarqube-build.yml


Spring Boot

  1. 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.xml to sonarqube-build.yml

  2. add
    <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>
    to pom.xml

  3. to 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

  1. add
    - run: npm ci
    - name: Unit Tests with Coverage
    run: npm run test:unit -- --coverage --testResultsProcessor=jest-sonar-reporter
    to sonarqube-build.yml

  2. create jest.config.js in top directory

  3. add
    module.exports = {
        preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
    };
    to jest.config.js

  4. execute vue add unit-jest

  5. type y

  6. execute npm install jest jest-sonar-reporter ts-jest @vue/cli-service @vue/cli-plugin-typescript @types/jest --save-dev

  7. file folder /tests/unit/example.spec.ts

  8. add
    describe('Example', () => {
        test('true is true', () => {
            expect(true).toBeTruthy();
        });
    });
    to /tests/unit/example.spec.ts