Автономные инструменты Jacoco Maven - Tomcat

дебаджйоти махапатро:

Я пытаюсь получить отчет о покрытии кода для интеграционных тестов. Плагин Jacoco maven может обеспечить покрытие кода для модульных тестов, но дает 0% покрытие для интеграционных тестов. Интеграционные тесты затрагивают остальные конечные точки api приложения, которое было развернуто в tomcat.

Мой плагин maven jacoco и плагин surefire выглядят так.

<plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>prepare-agent-integration</id>
                    <goals>
                        <goal>prepare-agent-integration</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${project.build.directory}/target/jacoco-it.exec</dataFile>
                        <outputDirectory>${project.build.directory}/target/jacoco-ut</outputDirectory>
                    </configuration>
                </execution>
            </executions>

            <configuration>
                <systemPropertyVariables>
                    <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
                </systemPropertyVariables>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <!-- <skip>true</skip> -->
                <!-- <systemPropertyVariables> <jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile> 
                    </systemPropertyVariables> -->
            </configuration>
            <!-- <configuration> <skip>true</skip> </configuration> -->
            <executions>
                <execution>
                    <id>unit-tests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <!-- Never skip running the tests when the test phase is invoked -->
                        <!-- <skip>true</skip> -->
                        <argLine>@{argLine}
                            -javaagent:c:\\iat\\mavenrepository\\org\\jacoco\\org.jacoco.agent\\0.7.10-SNAPSHOT\\org.jacoco.agent-0.7.10-SNAPSHOT-runtime.jar=destfile=C:\\Users\\dmahapat\\Workspaces\\MyEclipse
                            2016 CI\\JaxRsApp\\target\\jacoco.exec</argLine>
                        <includes>
                            <include>**/*UnitTest.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/*IntegrationTest.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                        <!-- Never skip running the tests when the integration-test phase 
                            is invoked -->
                        <!-- argLine>-javaagent:$WORKSPACE/target/lib/jacoco-agent-0.7.9.jar=includes=*,destfile=*/jacoco-coverage.exec,append=false</argLine -->
                        <skip>false</skip>
                        <argLine>@{argLine}
                            -javaagent:c:\\iat\\mavenrepository\\org\\jacoco\\org.jacoco.agent\\0.7.10-SNAPSHOT\\org.jacoco.agent-0.7.10-SNAPSHOT-runtime.jar=destfile=C:\\Users\\dmahapat\\Workspaces\\MyEclipse
                            2016 CI\\JaxRsApp\\target\\jacoco-it.exec
                        </argLine>

                        <includes>
                            <include>**/*IntegrationTest.java</include>
                        </includes>
                        <excludes>
                            <exclude>**/*UnitTest.java</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Я выполняю модульные тесты на этапе тестирования и интеграционные тесты на этапе тестирования интеграции. Последняя ошибка, которую я получаю, - «Пропуск выполнения JaCoCo из-за отсутствия файла данных выполнения».

дебаджйоти махапатро:

С помощью Евгения я проделал эту работу. Изменен сервер на glassfish и ide на intellij для упрощения отладки.

Запустите сервер Glassfish со следующими параметрами JVM.

-DargLine=-javaagent:c:/iat/mavenrepository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=C:/dmahapat_JaxRsApp/target/coverage-reports/jacoco-it.exec

Обновленный пом

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.mathworks</groupId>
<artifactId>JaxRsApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JaxRsApp</name>

<build>
    <finalName>JaxRsApp</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>add-test-source</id>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${project.basedir}\src\integration-test\java</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-resource</id>
                    <goals>
                        <goal>add-test-resource</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <!-- Don't forget <directory> label -->
                                <directory>${project.basedir}\src\integration-test\resources</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.9</version>
            <executions>
                <!--
                    Prepares the property pointing to the JaCoCo runtime agent which
                    is passed as VM argument when Maven the Surefire plugin is executed.
                -->
                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                        <!--
                            Sets the name of the property containing the settings
                            for JaCoCo runtime agent.
                        -->
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <!--
                    Ensures that the code coverage report for unit tests is created after
                    unit tests have been run.
                -->
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                    </configuration>
                </execution>

                <execution>
                    <id>pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <destFile>${project.build.directory}/coverage-reports/jacoco-it.exec</destFile>
                        <!--
                            Sets the name of the property containing the settings
                            for JaCoCo runtime agent.
                        -->
                        <propertyName>failsafeArgLine</propertyName>
                    </configuration>
                </execution>
                <!--
                    Ensures that the code coverage report for integration tests after
                    integration tests have been run.
                -->
                <execution>
                    <id>post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <!-- Sets the path to the file which contains the execution data. -->
                        <dataFile>${project.build.directory}/coverage-reports/jacoco-it.exec</dataFile>
                        <!-- Sets the output directory for the code coverage report. -->
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
                    </configuration>
                </execution>
            </executions>

        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
               <argLine>${surefireArgLine}</argLine>
                <excludes>
                    <exclude>**/*IntegrationTest*</exclude>
                </excludes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.20.1</version>
            <configuration>
              <argLine>${failsafeArgLine}</argLine>
                <includes>
                    <include>**/*IntegrationTest.java</include>
                </includes>
                <excludes>
                    <exclude>**/*UnitTest.java</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>integration-tests</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.5</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpmime -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.5.3</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.8.7</version>
    </dependency>
</dependencies>
<properties>
    <jersey.version>2.25.1</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

</properties>

Эта статья взята из Интернета, укажите источник при перепечатке.

Если есть какие-либо нарушения, пожалуйста, свяжитесь с[email protected] Удалить.

Отредактировано в
0

я говорю два предложения

0обзор
Войти в системуУчаствуйте в комментариях

Статьи по теме

Maven / Jacoco - как получить объединенный отчет после успешных тестов и слияния файлов данных jacoco?

Конфигурация Maven Jacoco для многомодульных проектов

Можно ли запускать плагин JaCoCo maven только во время жизненного цикла сайта?

Покрытие кода в сборке maven - Пропуск выполнения JaCoCo из-за отсутствия каталога классов

Охват многомодульного проекта Jacoco Maven

maven jacoco: не генерируется отчет о покрытии кода

Проблемы с настройкой JaCoCo в Maven

JaCoCo с Maven - отсутствует файл данных исполнения

Конфигурация Maven Jacoco - исключить классы / пакеты из отчета, не работающего

Maven Jacoco - многомодульный проект. Какая самая простая (централизованная?) Настройка?

Создание отчета о покрытии кода JaCoCo с помощью Maven

Как проверить минимальное покрытие кода для многомодульного проекта maven с помощью jacoco?

Как указать формат вывода для плагина jacoco для maven?

Получение покрытия кода моего приложения с помощью Java-агента JaCoCo на Tomcat

Как настроить многомодульный Maven + Sonar + JaCoCo для выдачи объединенного отчета о покрытии?

Как интегрировать автономные исполняемые файлы JaCoCo из многопроектной сборки Maven в SonarQube

Запуск jacoco проверки цели с Maven 3.5

jacoco-maven-plugin, не исключая тестовые классы

Как я могу исключить файлы покрытия кода SonarQube, используя плагин JaCoCo maven

Maven Jacoco - объедините все результаты тестов в 1 обзор

Невозможно использовать аргументы jacoco JVM и надежные аргументы JVM вместе в maven

Как я могу интегрировать отчеты Jacoco с SonarQube без использования maven?

Как я могу интегрировать отчеты Jacoco с SonarQube без использования maven?

Как настроить Jacoco с помощью SonarQube и Maven в Jenkins

Создание покрытия кода с помощью JaCoCo и плагина spring-boot-maven

Ошибка развертывания Maven Tomcat

Как остановить maven tomcat

Почему бы не использовать / в качестве контекстного пути в maven tomcat?

Докер с Maven и Tomcat

TOP список

  1. 1

    Распределение Рэлея Curve_fit на Python

  2. 2

    How to click an array of links in puppeteer?

  3. 3

    В типе Observable <unknown> отсутствуют следующие свойства из типа Promise <any>.

  4. 4

    Как добавить Swagger в веб-API с поддержкой OData, работающий на ASP.NET Core 3.1

  5. 5

    Нарисуйте диаграмму с помощью highchart.js

  6. 6

    无法通过Vue在传单中加载pixiOverlay

  7. 7

    Отчеты Fabric Debug Craslytic: регистрация, отсутствует идентификатор сборки, применить плагин: io.fabric

  8. 8

    Статус HTTP 403 - ожидаемый токен CSRF не найден

  9. 9

    TypeError: store.getState não é uma função. (Em 'store.getState ()', 'store.getState' é indefinido, como posso resolver esse problema?

  10. 10

    ContentDialog.showAsync в универсальном оконном приложении Win 10

  11. 11

    В UICollectionView порядок меняется автоматически

  12. 12

    Merging legends in plotly subplot

  13. 13

    Elasticsearch - Нечеткий поиск не дает предложения

  14. 14

    Bogue étrange datetime.utcnow()

  15. 15

    Объединение таблиц в листе Google - полное соединение

  16. 16

    Single legend for Plotly subplot for line plots created from two data frames in R

  17. 17

    как я могу удалить vue cli 2?

  18. 18

    ViewPager2 мигает / перезагружается при смахивании

  19. 19

    Компилятор не знает о предоставленных методах Trait

  20. 20

    JDBI - В чем разница между @define и @bind в JDBI?

  21. 21

    проблемы с AVG и LIMIT SQL

популярныйтег

файл