REST Assured API Automation Testing Ⅰ - Getting Started
持续创作,加速成长!这是我参与「掘金日新计划 · 6 月更文挑战」的第24天,点击查看活动详情
Section 1: What is Rest Assured?
Rest Assured is a Java Library that can testing Apis, also called RESTful Apis. You can write test cases using the given
, when
, then
which human are readable and can be easily understood.
As introduced on the official website REST Assured brings the simplicity of using dynamic languages into the Java domain
. Rest Assured uses groovy under the hood. Rest Assured can used along with unit testing framework like Junit, TestNG and also with the Cucumber BDD
which BDD stand for Behavioral Driver Development
.
You can find more documents on the Rest Assured homepage.
Section 2: Setup for Rest Assured Project
Below is the list of tools or libraries we gonna need to creating a Rest Assured project.
- Java JDK - 8
- TestNG
- IntelliJ
- Maven
We gonna use JDK - 8 as the default version of Java and the TestNG for the Unit Testing framework, IntelliJ as the IDE and build the project by Maven 3.6.3.
Launch the IntelliJ and click Create New Project
Choose maven to build the Project and click Next button
Then fill the project name and GoupId, ArtifactId, then click Finish button
pom.xml is the place where we add dependencies, first we created dependencies tag, then add Rest Assured and TestNG dependencies, you check the offical doucment Getting Stated page or search from the maven central repository. Below are the REST Assured and TestNG dependencies.
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.0</version>
<scope>test</scope>
</dependency>
</dependencies>
REST Assured includes JsonPath and XmlPath as transitive dependencies, so we don't have to add those again, and you can check the libaries form External Dependices that automatically download by IntelliJ.
Create new package under test package named com.restassured
, create a java class named QuickstartTest
then create a Java class testAlpha
and add TestNG annotation @Test
.
public class QuickstartTest {
@Test
public void testAlpha(){
}
}
We need to add the import, but as static import. Importing these rest assured classes as static imports has some advantages even though it's generally not recommendedto import classes as static imports, then we can using the given when then statement
import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
public class QuickstartTest {
@Test
public void testAlpha(){
given().
when().
then();
}
}
then Run the testAlpha method, we got the test reslut on the console bottom of the IntelliJ
Why use static imports
with static import, we don't have to use the class name along with the middle name. The given
method class name is RestAssured, we are using static keyword for importing the classes
相关文章
- 了解下 Kuberentes Gateway API
- 观点:Service Mesh和API网关正在逐步融合
- nodeJs基础Api
- 腾讯会议Rest API网络研讨会封面/会议背景图片设置结果返回变为异步方式变更通知
- API和Web Api
- Openstack中api参数传递机制
- 个人号微信api接口开发_API接口授权系统php源码
- 面试官:什么是Java优雅埋点API的设计思路?
- 公众号通过api发送小程序消息
- 分布式系统核心:REST风格的架构,REST成熟度模型及REST API管理
- 【ES三周年】吊打Elasticsearch 和Java API(进阶保姆级教程-3)
- 使用OAuth2保护API
- 利用Java API通过路径过滤上传多文件至HDFS详解大数据
- JBPM4中的ProcessEngine与Service API详解编程语言
- 探索Linux系统 API 的乐趣(linux系统api)
- JDBC API ResultSet接口(记录集接口)
- MySQL中文API:数据操作更便捷(mysql中文api)
- 简易指南:轻松使用Redis 常用API(redis常用api)
- MSSQL API调用:解放数据开发者(mssql的api调用)
- MySQL的API关闭全面调控(api关闭mysql)
- 快速下载API数据使用MySQL实现(mysql下载api数据)
- android开发教程之获取使用当前api的应用程序名称