Вопрос

I am doing code coverage Testing using jmockit. I need to exclude some classes from code coverage. The VM argument used to exclude classes in eclipse is

-Djmockit-coverage-excludes=com\.jmockit\.beans\..+

I referred this documentation. What I need now is, I need to exclude multiple classes. How can I combine packages and pass it as an argument say -Djmockit-coverage-excludes=packageA+packageB to exclude both the packages from code coverage.

Это было полезно?

Решение

You can use the | character to separate multiple regular expressions, each for a specific package or group of packages. For example:

-Djmockit-coverage-excludes=packageA\..+|packageB\..+|com\.mydomain\..+

Другие советы

The above answer by Rogério does not work in windows (good work on JMockit btw) as the | character is a special character. To escape the | you need to add ^.

e.g.

-Djmockit-coverage-excludes=packageA\..+^|packageB\..+^|com\.mydomain\..+

This makes this solution not cross platform. For us this is a real issue as development is on Windows and the build server is linux.

Can the coverage plugin read configuration properties from the plugin in the pom other than adding these command line arguments, if so, what are the tags?

EDIT: I have updated my POM to cope with this in this way:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
    <argLine>-XX:MaxPermSize=256m -XX:-UseSplitVerifier ${jmockit-coverage-options}</argLine>
</configuration>
</plugin>

...

<profiles>
    <profile>
        <id>os-windows</id>
        <activation>
            <os>
                <family>windows</family>
            </os>
        </activation>
        <properties>
            <!-- See: http://code.google.com/p/jmockit/issues/detail?id=322 -->
            <!-- See: http://code.google.com/p/jmockit/issues/detail?id=323 -->
            <jmockit-coverage-options>-Djmockit-coverage-outputDir=target/coverage-report -Djmockit-coverage-classes=PackageC\..+ -Djmockit-coverage-excludes=packageA\..+^|packageB\..+^|com\.mydomain\..+</jmockit-coverage-options>
        </properties>
    </profile>

    <profile>
        <id>os-unix</id>
        <activation>
            <os>
                <family>unix</family>
            </os>
        </activation>
        <properties>
            <!-- See: http://code.google.com/p/jmockit/issues/detail?id=322 -->
            <jmockit-coverage-options>-Djmockit-coverage-outputDir=target/coverage-report -Djmockit-coverage-classes=PackageC\..+ -Djmockit-coverage-excludes=packageA\..+|packageB\..+|com\.mydomain\..+</jmockit-coverage-options>
        </properties>
    </profile>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top