Maven通过Jacoco生成单元测试覆盖率数据,无法生成jacoco.exec

由于jacoco-maven-plugin与maven-surefire-plugin插件均使用argLine参数,导致surefire覆盖了jacoco的参数,而无法生成jacoco.exec,maven报错:Skipping JaCoCo execution due to missing execution data file

在jacoco中加入propertyName参数,在surefire中的argLine中引入,即可解决此问题,pom配置如下:      

           <!-- 单元覆盖率插件-->
           <plugin>
              <groupId>org.jacoco</groupId>
              <artifactId>jacoco-maven-plugin</artifactId>
              <version>0.7.9</version>
              <executions>
                  <execution>
                  <id>pre-unit-test</id>
                  <goals>
                      <goal>prepare-agent</goal>
                  </goals>
                  <configuration>
                      <propertyName>jacocoArgLine</propertyName>
                  </configuration>
                  </execution>
                  <execution>
                  <id>post-unit-test</id>
                  <phase>package</phase>
                  <goals>
                      <goal>report</goal>
                  </goals>
                  </execution>
              </executions>
            </plugin>
            <!-- 排除部分类的单元测试,如controller-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <argLine>-Xmx256M ${jacocoArgLine}</argLine>
                    <skip>false</skip>
                    <testFailureIgnore>false</testFailureIgnore>
                    <includes></includes>
                    <excludes>
                        <!-- 由于测试controller类需要启动auth应用进行登录请求,故剔除 -->
                        <exclude>**/controller/*ControllerTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值