Maven 测试

maven自动测试主要实现下面2个功能

1.测试指定类 

2.测试指定类的指定方法

 

实现方法:

先在pom.xml添加测试插件代码(2.8),maven3.0.3自带的 maven-surefire-plugin为2.7.2经测试无法实现上面的功能

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.8</version>
        <configuration>
          <includes>
            <include>**/*Test.java</include> 包含所有后缀为Test.jave的类
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
 

1.测试指定类 

  语法:

mvn test -Dtest=className 或 mvn -Dtest=className test

例: SimpleTest.java  Simple1Test.java Simple2Test.java

 

执行单个:mvn test -Dtest=SimpleTest

 

执行多个:mvn test -Dtest=SimpleTest,Simple1Test,Simple2Test

 

运用通配符:mvn test -Dtest=Simple*Test

 

结合写法:mvn -Dtest=SimpleTest,Simple*Test test

 

2.测试指定类的指定方法

 

  语法:

mvn test -Dtest=className#method 或 mvn -Dtest=className#method test

例: SimpleTest.java 方法 apptest

 

执行单个:mvn test -Dtest=SimpleTest#apptest

 

 

运用通配符:mvn test -Dtest=SimpleTest#*test* 执行测试类中包含test的所有方法 

 

 

更多:includesexcludes 配置请查看 http://maven.apache.org/plugins/maven-surefire-plugin/examples/inclusion-exclusion.html

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值