1

maven で maven-surefire-plugin バージョン 2.17 を使用しています。

junit テストを分析するために jacoco-maven-plugin を使用しています。

私の pom.xml にセットアップされた jacoco プラグインは次のようになります。

    <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.6.201602180812</version>
            <executions>
                <execution>
                    <id>agent-for-ut</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                        <append>true</append>
                    </configuration>
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

src/main/java/something/excel の下に次のようなクラスがあります。

package something.excel;

public class VDHTCStyle
{
    public int doSomething() {
        int i=0;
        return i+7;
    }
}

src/test/java/something/excel の下にある私のテスト クラスは次のようになります。

package something.excel;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class VDHTCStyleStyleTest
{
    private VDHTCStyleStyle vDHTCStyleStyle;

    @Before
    public void setUp()
    {
        vDHTCStyleStyle = new VDHTCStyleStyle();
    }

    @Test
    public void shouldDoSomething() {
        int something = vDHTCStyleStyle.doSomething();
        assertEquals(something, 7);
    }

}

これを実行すると

mvn clean install

ログにこれが表示されます:

[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ xxxxx ---
[INFO] Surefire report directory: /var/lib/jenkins/workspace/xxxx/modules/xx/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running something.excel.VDHTCStyleTest
|classnames | 2.2.3 | A simple utility for conditionally joining classNames together|
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.062 sec - in something.excel.VDHTCStyleTest 

生成された jacoco-ut レポート ファイルを見ると、次のようになっています。

GROUP,PACKAGE,CLASS,INSTRUCTION_MISSED,INSTRUCTION_COVERED,BRANCH_MISSED,BRANCH_COVERED,LINE_MISSED,LINE_COVERED,COMPLEXITY_MISSED,COMPLEXITY_COVERED,METHOD_MISSED,METHOD_COVERED
Module: xxx,something.excel,VDHTCStyleStyle,9,0,0,0,3,0,2,0,2,0

私が理解しているように、行、命令、分岐、またはメソッドのいずれもカバーされていないと考えています。

なんで?ヘルプ :)

4

1 に答える 1

2

問題は、マルチモジュール プロジェクトで 2 回指定すると、maven-surefire-plugin が予期しない動作をすることです。

私の親 pom はビルド セクションにあり、子モジュール pom もビルド セクションにありました。そのため、テストを実行しているように見えましたが、子モジュールのカバレッジは常に 0 でした。

修正は、子モジュール pom から maven-surefire-plugin を削除し、親 pom のビルド セクションにのみ含めることでした。

問題が解決しました。

于 2016-06-06T17:43:08.283 に答える