欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

maven集成单元测试插件 单元测试maven 

程序员文章站 2022-03-13 11:25:17
...
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>
</executions>
</plugin>
<!-- cobertura插件 ,取消不需要计算覆盖率的类 -->
<plugin>
<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>
相关标签: 单元测试 maven