maven integration unit test plugin

1.maven不可允许忽略单元测试
2.引用jacoco.version
<jacoco.version>0.7.7.201606060606</jacoco.version>
3.maven依赖jar包
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.4</version>
<scope>test</scope>
</dependency>
<!-- test jndi datasource -->

4.maven插件
<plugins>
<!-- 单元测试统计需要的插件开始 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<!-- <useSystemClassLoader>false</useSystemClassLoader> ??? -->
<suiteXmlFiles>
<suiteXmlFile>src/test/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-XX:NewSize=256m -XX:MaxNewSize=512m -XX:PermSize=256m
-XX:MaxPermSize=512m</argLine>
<testFailureIgnore>true</testFailureIgnore>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
</configuration>
</execution> <plugin> <!-- cobertura plugin, cancel classes that do not need to calculate coverage --> </plugin>
</executions>



<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<!-- <instrumentation> <includes> <include>**/*Impl.class</include>
</includes> </instrumentation> -->
<check>
<branchRate>75</branchRate>
<lineRate>75</lineRate>
<haltOnFailure>false</haltOnFailure>
<totalBranchRate>75</totalBranchRate>
<totalLineRate>75</totalLineRate>
<packageLineRate>75</packageLineRate>
<packageBranchRate>75</packageBranchRate>
<!-- <regexes> <regex> <pattern>com.example.reallyimportant.*</pattern>
<branchRate>90</branchRate> <lineRate>80</lineRate> </regex> <regex> <pattern>com.example.boringcode.*</pattern>
<branchRate>40</branchRate> <lineRate>30</lineRate> </regex> </regexes> -->
</check>
</configuration>
<!-- <executions> <execution> <goals> <goal>clean</goal> <goal>check</goal>
</goals> </execution> </executions> -->
</plugin>
<!-- 单元测试统计需要的插件结束 -->
</plugins>

5.src/test目录下创建testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
<suite name="Suite1" verbose="1" >
  <test name="app" >
    <packages> 
          <package name="com.suning.fsp.weixin.controller.portal.app.weChat.test" /> 
   </packages>
  </test>

</suite>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326093917&siteId=291194637