首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >集成JaCoCo、Arquillian和请放心为我提供了0%的代码覆盖率。

集成JaCoCo、Arquillian和请放心为我提供了0%的代码覆盖率。
EN

Stack Overflow用户
提问于 2016-01-18 11:39:46
回答 1查看 2.2K关注 0票数 2

我正在使用JaCoCo,Arquillian和放心测试我的RESTFul API。问题是我的JaCoCo报告中有0%的代码覆盖率。我正在为测试用例使用maven配置文件,获取一个通配符实例,在JVM上部署它,部署我的API,然后运行测试。

我已经做了一些研究,并达到了这样的程度: JaCoCo必须运行在运行.war文件的同一个JVM上(这是我的情况)。

由于JaCoCo在同一个JVM上,我认为覆盖率不会发生任何变化,但它给我带来了0%。

有人能帮我吗?

遵循我在pom.xml上的maven配置文件:

代码语言:javascript
复制
<profile>
        <id>test-postgresql</id>

        <properties>
            <datasource.driver>postgresql.jar</datasource.driver>
            <datasource.driverClass>org.postgresql.Driver</datasource.driverClass>
            <datasource.url>jdbc:postgresql://localhost:5432/security-test</datasource.url>
            <datasource.user>postgres</datasource.user>
            <datasource.password>a</datasource.password>
        </properties>

        <dependencies>
            <!-- WildFly Container Managed -->
            <dependency>
                <groupId>org.wildfly</groupId>
                <artifactId>wildfly-arquillian-container-managed</artifactId>
                <version>${wildfly.version}</version>
                <scope>test</scope>
            </dependency>

            <!-- PostgreSQL JDBC Driver -->
            <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>${jdbc.postgresql.version}</version>
                <scope>test</scope>
            </dependency>
        </dependencies>

        <build>
            <plugins>
                <!-- Dependency Plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>${plugin.dependency.version}</version>
                    <executions>
                        <!-- Unpack WildFly -->
                        <execution>
                            <id>unpack-wildfly</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>org.wildfly</groupId>
                                        <artifactId>wildfly-dist</artifactId>
                                        <version>${wildfly.version}</version>
                                        <type>zip</type>
                                        <overWrite>false</overWrite>
                                        <outputDirectory>target</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>

                        <!-- Deploy JDBC Driver -->
                        <execution>
                            <id>copy-driver</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>postgresql</groupId>
                                        <artifactId>postgresql</artifactId>
                                        <version>${jdbc.postgresql.version}</version>
                                        <type>jar</type>
                                        <overWrite>false</overWrite>
                                        <outputDirectory>target/wildfly-${wildfly.version}/standalone/deployments</outputDirectory>
                                        <destFileName>${datasource.driver}</destFileName>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- Skip Unit Tests -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${plugin.surefire.version}</version>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>

                <!-- Integration Tests -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>${plugin.failsafe.version}</version>
                    <configuration>
                        <argLine>${jacoco.agent.it.arg}</argLine>
                        <redirectTestOutputToFile>false</redirectTestOutputToFile>
                        <systemPropertyVariables>
                            <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                            <jboss.home>${project.basedir}/target/wildfly-${wildfly.version}</jboss.home>
                            <module.path>${project.basedir}/target/wildfly-${wildfly.version}/modules</module.path>
                        </systemPropertyVariables>
                        <skipTests>false</skipTests>
                        <includes>
                            <include>**/test/**/*.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>integration-test</id>
                            <goals>
                                <goal>integration-test</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>verify integration-test</id>
                            <goals>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- Liquibase Plugin (Drop Database) -->
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>${liquibase.version}</version>
                    <configuration>
                        <driver>${datasource.driverClass}</driver>
                        <url>${datasource.url}</url>
                        <username>${datasource.user}</username>
                        <password>${datasource.password}</password>
                        <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                    </configuration>
                    <executions>
                        <execution>
                            <id>drop-database</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>dropAll</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <!-- JaCoCo Plugin -->
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${plugin.jacoco.version}</version>
                    <dependencies>
                        <!-- JaCoCo -->
                        <dependency>
                            <groupId>org.jacoco</groupId>
                            <artifactId>org.jacoco.core</artifactId>
                            <version>${plugin.jacoco.version}</version>
                        </dependency>

                        <!-- Arquillian JaCoCo -->
                        <dependency>
                            <groupId>org.jboss.arquillian.extension</groupId>
                            <artifactId>arquillian-jacoco</artifactId>
                            <version>1.0.0.Alpha8</version>
                        </dependency>
                    </dependencies>
                    <configuration>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>jacoco-agent</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>prepare-agent-integration</goal>
                            </goals>
                            <configuration>
                                <destFile>${sonar.jacoco.itReportPath}</destFile>
                                <propertyName>jacoco.agent.it.arg</propertyName>
                                <append>true</append>
                            </configuration>
                        </execution>

                        <execution>
                            <id>jacoco-report</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>report-integration</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-26 16:18:56

当Arquillian启动容器时,我不得不配置JaCoCo代理。实际上,我的jacoco插件变成了:

pom.xml

代码语言:javascript
复制
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${plugin.jacoco.version}</version>
    <executions>
        <execution>
            <id>jacoco-prepare</id>
            <phase>validate</phase>
            <goals>
                <goal>prepare-agent-integration</goal>
            </goals>
            <configuration>
                <propertyName>jacoco.agent</propertyName>
            </configuration>
        </execution>
        <execution>
            <id>jacoco-report</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>report-integration</goal>
            </goals>
        </execution>
    </executions>
</plugin>

在arquillian.xml参数中,在"javaVmArguments“属性的末尾添加${jacoco.agent}变量。如下所示:

代码语言:javascript
复制
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=10000 -Xms512m -Xmx1024m -XX:MaxPermSize=512m ${arquillian.debug} ${jacoco.agent}</property>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34853850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档