1

Есть java проект с junit тестами. Проект подключен к Jenkins. В Jenkins выполняются тесты. часть кода из Jenkinsfile:

stage('test') {
        app.withRun('') {
            c ->
                parallel 'junit test': {
                    app.inside {
                        sh 'mvn test'
                        junit '**/surefire-reports/**/*.xml'
                    }
                }, 'integration test': {
                    app.inside {
                        sh 'mvn -P=systest test'
                        junit '**/surefire-reports/**/*.xml'
                    }
                }
        }
    }

Но также необходимо получить процент покрытия кода тестами. Как это можно сделать?

2 ответа 2

1

Надо добавит в проект jacoco-maven-plagin и эти строчки в jenkins-pipeline

stage('Test') {
    sh "mvn clean org.jacoco:jacoco-maven-plugins:prepare-agent package"
    // Публикуем отчет о покрытии кода в Jenkins 
    jacoco()
}
5
1

Добавить плагин для покрытия в maven, что-то типа:

<build>
    <plugins>
        ...
        <!-- Code Coverage report generation -->
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>generate-code-coverage-report</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Добавить/настроить плагин в Jenkins:JaCoCo Plugin

Это один из вариантов, на самом деле вариантов много

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.