jacoco 多个 module 运行 code coverage 测试

别不相信,就这么简单,如果运行不成功,那就是加入插件的parent pom.xml有可能是maven repsitry中的文件。
parent pom.xml 中的中加入如下的插件:

<plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-surefire-pluginartifactId>
                <version>2.19.1version>
                <configuration>
                    <skipTests>falseskipTests>
                configuration>
            plugin>
<plugin>

<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-failsafe-pluginartifactId>
<version>2.19.1version>
<dependencies>
    <dependency>
                     <groupId>org.apache.maven.surefiregroupId>
                        <artifactId>surefire-junit47artifactId>
                        <version>2.19.1version>
                    dependency>
                dependencies>
                <configuration>
                    <forkCount>4forkCount>
                    <reuseForks>falsereuseForks>
                    <skip>trueskip>
                configuration>
                <executions>
                    <execution>
                        <id>integration-testid>
                        <goals>
                            <goal>integration-testgoal>
                        goals>
                    execution>
                    <execution>
                        <id>verifyid>
                        <goals>
                            <goal>verifygoal>
                        goals>
                    execution>
                executions>
            plugin>
            <plugin>
                <groupId>org.jacocogroupId>
                <artifactId>jacoco-maven-pluginartifactId>
                <version>0.7.9version>
                <configuration>
                    <destFile>target/coverage-reports/jacoco-unit.execdestFile>
                    <dataFile>target/coverage-reports/jacoco-unit.execdataFile>
                configuration>
                <executions>
                    <execution>
                        <id>jacoco-initializeid>
                        <goals>
                            <goal>prepare-agentgoal>
                        goals>
                    execution>
                    <execution>
                        <id>jacoco-siteid>
                        <phase>testphase>
                        <goals>
                            <goal>reportgoal>
                        goals>
                    execution>
                executions>
            plugin>

maven-surefire-plugin中的skiptest设置为false,用来运行单元测试。
jacoco中的Execution用来对应maven的goal,可以是test,verify。还有集成测试的选项。
运行 mvn clean test -Dmaven.test.failure.ignore=true
生成的report 在 target /site/jacoco下,导航到文件下,去查看index.html就是了。

你可能感兴趣的:(测试技术)