Покрытие кода тестового набора JBoss AS 7 с использованием JaCoCo — нет данных в файлах jacoco.exec

Я пытаюсь получить информацию о JBoss AS 7. Вот моя ветка: https://github.com/OndraZizka/jboss-as/tree/TS-jacoco

Когда я запускаю mvn clean install -rf testsuite -DallTests -Dcoverage -fae, я получаю (почти) пустые jacoco.exec файлы - просто некоторые метаданные (размер - несколько байт). Используемая строка аргумента JVM:

-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=${jboss.home}/modules/**/*,excludes=${basedir}/target/classes/**/*,append=true,output=file

Эта строка передается в Arquillian для запуска JBoss AS 7. Тестовый набор запускается, аргумент передается (он появляется в файле boot.log AS7), но результирующий файл jacoco.exec имеет размер всего несколько байтов. Отчет, конечно же, не показывает покрытия.

Что я делаю не так?


person Ondra Žižka    schedule 24.01.2012    source источник
comment
jboss-7.x не имеет смысла. JBoss является подразделением компании. Это как если бы у вас была метка microsoft-XP. Пожалуйста, сохраните тег jboss-as7. Или, что еще лучше, переименуйте тег jboss-7.x в jboss-as7.   -  person Ondra Žižka    schedule 25.01.2012


Ответы (1)


Решено: параметры «включает» и «исключает» агента относятся к именам классов, а не к файлам.

Правильный аргумент агента JVM для моего случая:

-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=*,excludes=org.jboss.as.test.*,append=true,output=file

Мой подход состоял в том, чтобы настроить плагин maven jacoco для получения аргумента, а затем жестко закодировать свойство в pom.xml, поскольку свойство, сгенерированное плагином, не передается плагину Surefire.

    <profile>
        <id>ts.jacoco.profile</id>
        <activation><property><name>coverage</name></property></activation>
        <properties>
            <jvm.args.jacoco>-javaagent:${jbossas.ts.dir}/target/jacoco-jars/agent/jacocoagent.jar=destfile=${basedir}/target/jacoco.exec,includes=*,excludes=org.jboss.as.test.*,append=true,output=file</jvm.args.jacoco>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${version.jacoco.plugin}</version>
                    <executions>
                        <execution><id>ts.jacoco-prepare</id>
                            <phase>process-test-classes</phase>
                            <goals><goal>prepare-agent</goal></goals>
                            <configuration>
                                <append>true</append>
                                <destFile>target/jacoco.exec</destFile>
                                <includes>
                                    <include>*</include>
                                </includes>
                                <excludes>
                                    <exclude>org.jboss.as.test.*</exclude>
                                </excludes>
                                <output>file</output>
                                <propertyName>jvm.args.jacoco</propertyName>
                            </configuration>
                        </execution>
                        <!-- Doesn't work currently - waiting for JaCoCo to fix this. Moved to the Ant plugin execution. -->
                        <execution><id>ts.jacoco.report</id>
                            <phase>none</phase> <!-- post-integration-test -->
                            <goals><goal>report</goal></goals>
                            <configuration>
                                <dataFile>target/jacoco.exec</dataFile>
                                <outputDirectory>target/coverageReport</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <!-- Copy JaCoCo jars to have them for the Ant plugin. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <!-- Copy the ant tasks jar. Needed for ts.jacoco.report-ant . -->
                        <execution> <id>ts.jacoco.dep.ant</id> <goals><goal>copy</goal></goals> <phase>process-test-resources</phase> <inherited>false</inherited>
                            <configuration>
                                <artifactItems>
                                    <artifactItem><groupId>org.jacoco</groupId><artifactId>org.jacoco.ant</artifactId><version>${version.jacoco.plugin}</version></artifactItem>
                                </artifactItems>
                                <stripVersion>true</stripVersion>
                                <outputDirectory>${basedir}/target/jacoco-jars</outputDirectory>
                            </configuration>
                        </execution>
                        <!-- Copy the agent jar. Needed for ${jvm.args.jacoco} to have this jar on known path.
                             If the ts.jacoco-prepare worked and really put the value into the property, this might go away. -->
                        <execution> <id>ts.jacoco.dep.agent</id> <goals><goal>unpack</goal></goals> <phase>process-test-resources</phase> <inherited>false</inherited>
                            <configuration>
                                <artifactItems>
                                    <artifactItem><groupId>org.jacoco</groupId><artifactId>org.jacoco.agent</artifactId><version>${version.jacoco.plugin}</version></artifactItem>
                                </artifactItems>
                                <stripVersion>true</stripVersion>
                                <outputDirectory>${basedir}/target/jacoco-jars/agent</outputDirectory>
                            </configuration>
                        </execution>

                    </executions>
                </plugin>
                <!-- Ant plugin. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <executions>
                        <!-- DEBUG -->
                        <execution>
                            <id>ts.jacoco.debug</id>
                            <phase>post-integration-test</phase>
                            <goals><goal>run</goal></goals>
                            <inherited>false</inherited>
                            <configuration>
                                <target>
                                    <echo>Jacoco argline: ${jvm.args.jacoco}</echo>
                                    <echo>Jacoco jar: ${basedir}/target/jacoco-jars/org.jacoco.ant.jar</echo>
                                </target>
                            </configuration>
                        </execution>
                        <!-- Must be run using Ant due to https://sourceforge.net/tracker/?func=detail&aid=3474708&group_id=177969&atid=883354 -->
                        <execution>
                            <id>ts.jacoco.report-ant</id>
                            <phase>site</phase> <!-- post-integration-test -->
                            <goals><goal>run</goal></goals>
                            <inherited>false</inherited>
                            <configuration>
                                <target>
                                    <taskdef name="report" classname="org.jacoco.ant.ReportTask">
                                        <classpath path="${basedir}/target/jacoco-jars/org.jacoco.ant.jar"/>
                                    </taskdef>
                                    <echo>Creating JaCoCo test coverage reports...</echo>
                                    <mkdir dir="${basedir}/target/coverage-report"/>
                                    <report>
                                        <executiondata>
                                            <fileset dir="${basedir}">
                                                <include name="**/target/jacoco.exec"/>
                                            </fileset>
                                        </executiondata>
                                        <structure name="AS 7 project">
                                            <classfiles>
                                                <fileset dir="${jboss.dist}/modules">
                                                    <include name="**/*.jar"/>
                                                    <!-- We have 2.x in main. -->
                                                    <exclude name="com/sun/jsf-impl/1.*/**/*"/>
                                                    <!-- AS7-3383 - com/sun/codemodel vs. /1.0/com/sun/codemodel -->
                                                    <exclude name="com/sun/xml/**/*"/>
                                                    <exclude name="javax/faces/api/1.2/**/*"/>
                                                    <!-- AS7-3390 -->
                                                    <exclude name="org/apache/commons/beanutils/**/*"/>
                                                    <!-- AS7-3389 -->
                                                    <exclude name="org/python/jython/standalone/**/*"/>
                                                </fileset>
                                            </classfiles>
                                            <sourcefiles encoding="UTF-8">
                                                <fileset dir="${jbossas.project.dir}">
                                                    <include name="**/*.java"/>
                                                    <exclude name="testsuite/**/*.java"/>
                                                </fileset>
                                            </sourcefiles>
                                        </structure>
                                        <html destdir ="${basedir}/target/coverage-report/html"/>
                                        <xml destfile="${basedir}/target/coverage-report/coverage-report.xml"/>
                                        <csv destfile="${basedir}/target/coverage-report/coverage-report.csv"/>
                                    </report>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                    <dependencies>
                        <dependency>
                            <groupId>org.jacoco</groupId>
                            <artifactId>org.jacoco.ant</artifactId>
                            <version>${version.jacoco.plugin}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    </profile>
person Ondra Žižka    schedule 24.01.2012
comment
+1, можете ли вы опубликовать обновленные исключения и включения, пожалуйста. Кроме того, как вы думаете, должен ли jacoco иметь доступ к исходному коду, чтобы показать покрытие? - person Aravind Yarram; 25.01.2012
comment
Пожалуйста, обновите, потому что это скорее комментарий, который, скорее всего, приведет к закрытию слишком локализованного. - person casperOne; 25.01.2012