技术分享

maven multi-module(多模块)项目集成Jacoc

2019-04-30  本文已影响0人  六二疯子

单模块集成Jacoco比较简单,网上有很多教程,基本上也不会出现什么问题。

问题:

多模块项目中,测试用例在一个模块中,生成测试覆盖率报告只包含此模块中的类,其他模块中的类没有被分析到。

解决:

主要思路就是单独创建一个子模块,不需要有任何内容,只要pom.xml就行。在pom.xml添加其他所有子模块的dependency(所以build时需要执行到mvn install阶段,把其他所有子模块install到本地maven仓库中),使用jacoco-maven-plugin的goal:merge把各个子模块生成的jacoco.exec(plugin中不配置的话,默认叫这个)聚合成一个exec,再使用goal:report-aggregate生成report。

项目结构是这样的:

fe
-- fe
-- fe_business
-- fe_common
-- fe_facade
-- fe_service
-- fe_test
-- fe_web

其中test case在fe模块中,test case主要是使用mockMvc测试controller中的http接口。controller在fe_web模块,service层在fe_service模块,其他不介绍了。SpringBoot启动类在fe模块。
fe_test模块是为了集成Jacoco新建的。

parent pom关键配置如下:

    <properties>
        ... ...
        <itCoverageAgent></itCoverageAgent>
    </properties>
    ... ...
    <profiles>
        <profile>
            <id>jacoco</id>
            <properties>
                <spring.profiles.active>development</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <includes>
                                <include>**/TestUserServiceController.java</include>
                            </includes>
                            <skip>false</skip>
                            <argLine>${itCoverageAgent}</argLine>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.8.3</version>
                        <!--<configuration>-->
                            <!--&lt;!&ndash;指定生成 .exec 文件的存放位置&ndash;&gt;-->
                            <!--<destFile>target/jacoco.exec</destFile>-->
                            <!--&lt;!&ndash;Jacoco 是根据 .exec 文件生成最终的报告,所以需指定 .exec 的存放路径&ndash;&gt;-->
                            <!--<dataFile>target/jacoco.exec</dataFile>-->
                        <!--</configuration>-->
                        <executions>
                            <execution>
                                <id>prepare-unit-tests</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <!--<configuration>-->
                                <!--<destFile>${sonar.jacoco.reportPath}</destFile>-->
                                <!--</configuration>-->
                            </execution>

                            <!-- prepare agent for measuring integration tests -->
                            <execution>
                                <id>prepare-agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                                <phase>pre-integration-test</phase>
                                <configuration>
                                    <!--<destFile>${sonar.jacoco.itReportPath}</destFile>-->
                                    <propertyName>itCoverageAgent</propertyName>
                                </configuration>
                            </execution>
                            <!--<execution>-->
                                <!--<id>jacoco-site</id>-->
                                <!--<phase>test</phase>-->
                                <!--<goals>-->
                                    <!--<goal>report</goal>-->
                                <!--</goals>-->
                            <!--</execution>-->
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

maven-surefire-plugin是运行test case的,因为我只写了一个测试用例,所以使用includes指定具体的测试类。
jacoco-maven-plugin:prepare-agent是字节码插桩,生成单个module的jacoco.exec的。argline定义为属性并引用
<argLine>${itCoverageAgent}</argLine>是因为sure-fire argLine劫持prepare-agent的argLine??(暂不太懂 没研究)

fe-test pom.xml配置如下:

    <dependencies>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe_business</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe_common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe_facade</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe_service</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.example</groupId>
            <artifactId>fe_web</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>jacoco</id>
            <properties>
                <spring.profiles.active>development</spring.profiles.active>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.19.1</version>
                        <configuration>
                            <!-- Jacoco prepare-agent builds some command-line params without -->
                            <!-- which jacoco will not instrument. Hence it is important to add -->
                            <!-- those command-line params here (${argLine} holds those params) -->
                            <argLine>${itCoverageAgent} -Xms256m -Xmx2048m</argLine>
                            <forkCount>1</forkCount>
                            <runOrder>random</runOrder>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>report-aggregate</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>report-aggregate</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>merge-results</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>merge</goal>
                                </goals>
                                <configuration>
                                    <fileSets>
                                        <fileSet>
                                            <directory>${basedir}/../</directory>
                                            <includes>
                                                <include>**/target/jacoco.exec</include>
                                            </includes>
                                        </fileSet>
                                    </fileSets>
                                    <destFile>${basedir}/../target/aggregate.exec</destFile>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

jacoco-maven-plugin:merge用来把各个module生成的jacoco.exec合并成一个并命名为aggregate.exec,jacoco-maven-plugin:report-aggregate生成报告。

在parent pom所在目录中运行

mvn clean install -P jacoco > jacoco.log

-P jacoco指定运行的profile id是jacoco。
maven profile与springboot profile的区别
> jacoco.log表示把mvn构建日志输出到文件中,因为构建日志很长,输出到文件中便于排查问题。

D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master>set MAVEN_OPTS=-Xms256m -Xmx2048m 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for nl.deholtmans:module3:jar:1.0-SNAPSHOT
[WARNING] The expression ${version} is deprecated. Please use ${project.version} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] jacoco-multi-module-demo
[INFO] module1
[INFO] module2
[INFO] module3
[INFO] test-reporting
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jacoco-multi-module-demo 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jacoco-multi-module-demo ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-unit-tests) @ jacoco-multi-module-demo ---
[INFO] argLine set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\target\\jacoco.exec
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-agent) @ jacoco-multi-module-demo ---
[INFO] itCoverageAgent set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-tests) @ jacoco-multi-module-demo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (integration-tests) @ jacoco-multi-module-demo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ jacoco-multi-module-demo ---
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\pom.xml to D:\mvn_repo\nl\deholtmans\jacoco-multi-module-demo\1.0-SNAPSHOT\jacoco-multi-module-demo-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module1 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module1 ---
[INFO] Deleting D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-unit-tests) @ module1 ---
[INFO] argLine set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module1\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ module1 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ module1 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ module1 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ module1 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ module1 ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running DomainClass1Test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.212 sec - in DomainClass1Test

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ module1 ---
[INFO] Building jar: D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target\module1-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-agent) @ module1 ---
[INFO] itCoverageAgent set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module1\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-tests) @ module1 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (integration-tests) @ module1 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ module1 ---
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target\module1-1.0-SNAPSHOT.jar to D:\mvn_repo\nl\deholtmans\module1\1.0-SNAPSHOT\module1-1.0-SNAPSHOT.jar
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\pom.xml to D:\mvn_repo\nl\deholtmans\module1\1.0-SNAPSHOT\module1-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module2 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module2 ---
[INFO] Deleting D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-unit-tests) @ module2 ---
[INFO] argLine set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module2\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ module2 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ module2 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ module2 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ module2 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ module2 ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running DomainClass2Test
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.206 sec - in DomainClass2Test

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ module2 ---
[INFO] Building jar: D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target\module2-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-agent) @ module2 ---
[INFO] itCoverageAgent set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module2\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-tests) @ module2 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (integration-tests) @ module2 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ module2 ---
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target\module2-1.0-SNAPSHOT.jar to D:\mvn_repo\nl\deholtmans\module2\1.0-SNAPSHOT\module2-1.0-SNAPSHOT.jar
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\pom.xml to D:\mvn_repo\nl\deholtmans\module2\1.0-SNAPSHOT\module2-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module3 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module3 ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-unit-tests) @ module3 ---
[INFO] argLine set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module3\\target\\jacoco.exec
[INFO] 
[INFO] --- build-helper-maven-plugin:1.9.1:add-test-source (add-source) @ module3 ---
[INFO] Test Source directory: D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\src\functionaltest\java added.
[INFO] 
[INFO] --- build-helper-maven-plugin:1.9.1:add-test-resource (add-resource) @ module3 ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ module3 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ module3 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ module3 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\src\test\resources
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ module3 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 2 source files to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\target\test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ module3 ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running cucumbertest.UserTest

1 Scenarios (�[32m1 passed�[0m)
3 Steps (�[32m3 passed�[0m)
0m0.841s

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.033 sec - in cucumbertest.UserTest

Results :

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ module3 ---
[INFO] Building jar: D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\target\module3-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-agent) @ module3 ---
[INFO] itCoverageAgent set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\module3\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-tests) @ module3 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (integration-tests) @ module3 ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ module3 ---
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\target\module3-1.0-SNAPSHOT.jar to D:\mvn_repo\nl\deholtmans\module3\1.0-SNAPSHOT\module3-1.0-SNAPSHOT.jar
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\pom.xml to D:\mvn_repo\nl\deholtmans\module3\1.0-SNAPSHOT\module3-1.0-SNAPSHOT.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building test-reporting 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-reporting ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-unit-tests) @ test-reporting ---
[INFO] argLine set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\testing\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-reporting ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-reporting ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test-reporting ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-reporting ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ test-reporting ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-reporting ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\target\test-reporting-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (prepare-agent) @ test-reporting ---
[INFO] itCoverageAgent set to -javaagent:D:\\mvn_repo\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=D:\\iproject\\maven-multi-module-unittest-integrationtest-jacoco-master\\testing\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-tests) @ test-reporting ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-failsafe-plugin:2.18.1:verify (integration-tests) @ test-reporting ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:report-aggregate (report-aggregate) @ test-reporting ---
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module1\target\jacoco.exec
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module2\target\jacoco.exec
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\module3\target\jacoco.exec
[INFO] Analyzed bundle 'module1' with 1 classes
[INFO] Analyzed bundle 'module2' with 1 classes
[INFO] Analyzed bundle 'module3' with 1 classes
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.9:merge (merge-results) @ test-reporting ---
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\..\module1\target\jacoco.exec
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\..\module2\target\jacoco.exec
[INFO] Loading execution data file D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\..\module3\target\jacoco.exec
[INFO] Writing merged execution data to D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\..\target\aggregate.exec\aggregate.exec
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ test-reporting ---
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\target\test-reporting-1.0-SNAPSHOT.jar to D:\mvn_repo\nl\deholtmans\test-reporting\1.0-SNAPSHOT\test-reporting-1.0-SNAPSHOT.jar
[INFO] Installing D:\iproject\maven-multi-module-unittest-integrationtest-jacoco-master\testing\pom.xml to D:\mvn_repo\nl\deholtmans\test-reporting\1.0-SNAPSHOT\test-reporting-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] jacoco-multi-module-demo ........................... SUCCESS [  1.758 s]
[INFO] module1 ............................................ SUCCESS [  4.850 s]
[INFO] module2 ............................................ SUCCESS [  2.046 s]
[INFO] module3 ............................................ SUCCESS [  5.786 s]
[INFO] test-reporting ..................................... SUCCESS [  0.677 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15.266 s
[INFO] Finished at: 2019-04-30T11:17:26+08:00
[INFO] Final Memory: 25M/380M
[INFO] ------------------------------------------------------------------------

构建完成后在 fe_test/target/site 目录里查看报告
我只写了一个测试用例,代码覆盖率很低,但是覆盖到的3个module都已显示在报告中。


report.png

如有任何建议、或文中有错误请在评论区指出,谢谢

参考:

https://github.com/johan974/maven-multi-module-unittest-integrationtest-jacoco
http://www.lorenzobettini.it/2017/02/jacoco-code-coverage-and-report-of-multiple-eclipse-plug-in-projects/

上一篇下一篇

猜你喜欢

热点阅读