测试开发基础 mvn test | 利用 Maven Surefire Plugin 做测试用例基础执行管理

一、需求

在测试工作场景中,经常会遇到下面的问题:

  • 1、执行自动化测试用例的时候,只想指定某个测试类,或者某个方法,又或者某一类用例等,怎么办?

  • 2、想要和 Jenkins 一起进行持续集成,可是用例又不可能在 IDE 里面执行,怎么办?

这个时候就需要 Maven 登场了,利用 Maven 的Maven-Surefire-Plugin插件可以帮助我们完成上述的目标!它可以通过命令行的形式来管理我们要执行的用例。

二、环境

2.1 环境要求
  • Maven 3.x +

  • JDK 1.7 +

2.2 支持框架

对于我们测试来说,常接触的几个用例管理框架都支持(这里指 Java 技术栈)

  • Using TestNG

  • Using JUnit 5 Platform

  • Using JUnit

2.3 相关依赖
本文将以 Junit5 为例进行研究学习,所以下面的依赖添加也以 Junit5 为准。

常用到的 Junit5 相关依赖:

    <dependency>       <groupId>org.junit.platform</groupId>        <artifactId>junit-platform-launcher</artifactId>        <version>1.6.2</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.junit.platform</groupId>        <artifactId>junit-platform-runner</artifactId>        <version>1.5.1</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.junit.jupiter</groupId>        <artifactId>junit-jupiter-engine</artifactId>        <version>5.6.2</version>        <scope>test</scope>    </dependency>    <dependency>        <groupId>org.junit.vintage</groupId>        <artifactId>junit-vintage-engine</artifactId>        <version>5.6.2</version>        <scope>test</scope>    </dependency>

Maven-Surefire-Plugin:

<build>   <plugins>       <plugin>           <groupId>org.apache.maven.plugins</groupId>           <artifactId>maven-surefire-plugin</artifactId>           <version>2.22.0</version>       </plugin>       <plugin>           <groupId>org.apache.maven.plugins</groupId>           <artifactId>maven-compiler-plugin</artifactId>           <version>3.8.1</version>           <configuration>               <source>8</source>               <target>8</target>           </configuration>            </plugin>   </plugins></build>

指定编译 JDK 版本:

<properties>    <aspectj.version>1.8.10</aspectj.version>    <maven.compiler.source>1.8</maven.compiler.source>    <maven.compiler.target>1.8</maven.compiler.target></properties>

三、指定测试类

现有如下结构的测试类,在此基础上进行演示:

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值