LoginSignup
5

More than 5 years have passed since last update.

posted at

updated at

WildFly+jacocoでintegration-testのカバレッジ取得

概要

wildfly-maven-pluginとjacocoを使ってintegration-testのカバレッジを取得します。

環境

  • WildFly 8.0.0.Final
  • wildfly-maven-plugin 1.0.1.Final
  • jacoco-maven-plugin 0.7.0.201403182114

前提

wildfly-maven-pluginを使ったintegration testの内容にしたがって、WildFlyでintegration-testが実行できる状態になっている。

内容

  • pomに以下の設定を追加します。
    • jacocoプラグインを追加。
    • wildflyのjvmオプションにjacocoをjavaagentとして指定。
pom.xml
    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.0.201403182114</version>
            </plugin>            
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>1.0.1.Final</version>
                <configuration>
                    <jvmArgs>-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -javaagent:${user.home}/.m2/repository/org/jacoco/org.jacoco.agent/0.7.0.201403182114/org.jacoco.agent-0.7.0.201403182114-runtime.jar=destfile=${basedir}/target/jacoco.exec</jvmArgs>
                    <jbossHome>${wildflyPath}</jbossHome>
                    <serverConfig>standalone.xml</serverConfig>
                </configuration>

ポイントはjvmArgsの箇所。
mavenローカルリポジトリに配置されたjacoco agentを指定し、オプションに出力ファイル (jacoco.exec) を指定します。

  • integration-testを実行する。
$ mvn clean install

途中でintegration-testが実行されます。mvn integration-testでもいいのですが、テスト後にアプリケーションがアンデプロイされず残ってしまったのでinstallを実行しました。

  • jacocoのレポートを出力
$ mvn jacoco:report

integration-testで出力されたjacoco.execを使ってレポートが生成されます。

jacoco1.png

Missed InstructionsがC0 (命令網羅率) でMissed BranchesがC1 (条件網羅率) を表しています。

ドリルダウンしていくと、、、

jacoco2.png

こんな感じ。

緑:実行された命令。
赤:実行されなかった命令。
黄:分岐において一部のみ実行された命令。

embedded-glassfishでやっていた時は、pom側からjvmオプションを指定できなかったので、glassfish側にjavaagentを設定して手動でレポートを作っていました。
WildFlyならSonarと組み合わせて自動化できそう!

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
5