emma-logo、width = 220、height = 65


エマ

は無料のJavaコードカバレッジツールです。このチュートリアルでは、Mavenを使用してプロジェクトのEmmaコードカバレッジレポートを生成する方法と、EmmaレポートをMavenプロジェクトサイトに統合する方法について説明します。

1. Emmaコードカバレッジレポートを生成する

何もしないで、次のMavenコマンド

mvn emma:emma`を入力して

maven-emma-plugin`を実行してください。

c:\project> mvn emma:emma
//...
Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.53 sec
EMMA: locking coverage output file[C:\mkyong__projects\TestNG\coverage.ec]...
EMMA: runtime coverage data merged into[C:\mkyong__projects\TestNG\coverage.ec]{in 78 ms}

Results :

Tests run: 16, Failures: 0, Errors: 0, Skipped: 0
[INFO][INFO]<<< emma-maven-plugin:1.0-alpha-3:emma (default-cli) @ TestNG <<<[INFO][INFO]--- emma-maven-plugin:1.0-alpha-3:emma (default-cli) @ TestNG ---
processing input files ...
2 file(s) read and merged in 1 ms
writing[xml]report to[C:\mkyong__projects\TestNG\target\site\emma\coverage.xml]...
writing[html]report to[C:\mkyong__projects\TestNG\target\site\emma\index.html]...[INFO]------------------------------------------------------------------------[INFO]BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time: 4.004s[INFO]Finished at: Fri Jan 10 23:32:05 SGT 2014[INFO]Final Memory: 25M/307M[INFO]------------------------------------------------------------------------
C:\mkyong__projects\TestNG>

Mavenは `$ {project}/target/site/index.html`にあるコードカバレッジレポートを生成するためにコンパイルし、ユニットテストとEmmaプラグインを実行します。


Figure:Emmaコードカバレッジレポートのサンプル、

$ {project}/target/site/index.html

.


emma-code-coverage-report-1、width = 639、height = 301


図:詳細ページ.


emma-code-coverage-report-2、width = 640、height = 404

2. MavenサイトEmmaレポート

EmmaレポートをMavenプロジェクトサイトに統合するには、以下をレポートセクションに追加します。

pom.xml

 //...
  <reporting>
    <plugins>
    <!-- Normally, dependency report takes time, skip it -->
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-project-info-reports-plugin</artifactId>
    <version>2.7</version>

    <configuration>
          <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
    </configuration>
      </plugin>

     //integrate maven emma plugin to project site
      <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>emma-maven-plugin</artifactId>
    <version>1.0-alpha-3</version>
    <inherited>true</inherited>
      </plugin>

    </plugins>
  </reporting>

Mavenプロジェクトサイトを作成する

c:\project> mvn site
//...
Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.45 sec
EMMA: locking coverage output file[C:\mkyong__projects\TestNG\coverage.ec]...
EMMA: runtime coverage data merged into[C:\mkyong__projects\TestNG\coverage.ec]{in 38 ms}

Results :

Tests run: 16, Failures: 0, Errors: 0, Skipped: 0
//... Generating other reports[INFO]Generating "Project Summary" report    [INFO]Generating "Dependencies" report    [INFO]Generating "EMMA Test Coverage" report
processing input files ...
2 file(s) read and merged in 2 ms
writing[xml]report to[C:\mkyong__projects\TestNG\target\site\emma\coverage.xml]...
writing[html]report to[C:\mkyong__projects\TestNG\target\site\emma\index.html]...[INFO]------------------------------------------------------------------------[INFO]BUILD SUCCESS[INFO]------------------------------------------------------------------------[INFO]Total time: 8.488s[INFO]Finished at: Fri Jan 10 23:43:58 SGT 2014[INFO]Final Memory: 40M/1024M[INFO]------------------------------------------------------------------------

出力 – プロジェクトサイト、

$ {project}/site/index.html


maven-site-emma、width = 639、height = 297

3. Mavenビルドに統合する

また、ビルドセクションに “emma-maven-plugin”を含めることもできます。

pom.xml

 //...
  <build>

    <plugins>

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>emma-maven-plugin</artifactId>
        <version>1.0-alpha-3</version>
        <inherited>true</inherited>
        <executions>
          <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>instrument</goal>
            </goals>
          </execution>
        </executions>
     </plugin>

    </plugins>
  </build>

リンク://qa/emma-class-x-instrumented-appear/already/[クラスXは既に装備されているようです]エラーに気を付けてください。

参考文献

プラグイン]。

http://ja.wikipedia.org/wiki/Java


Code

Coverage__Tools[Javaコード

カバレッジツール]。リンク://qa/maven-cobertura-code-coverage-example/[Maven Cobertuna

コードカバレッジの例]

リンク://タグ/コードカバレッジ/[コードカバレッジ]リンク://タグ/emma/[emma]

maven site