自动化测试框架选型首先需要明确测试的目标,同时要考虑测试组成员的技能水平;同时一个好的框架应该是有易用性,可重用性,易维护性和可扩展性
技术准备
语言:Java
框架:Spring,Junit,Cucumber
工具准备
idea,maven,git
开始
-
在pom文件中引入依赖包:
org.springframework spring-web ${spring.version}<dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-core</artifactId> <version>4.0.0</version> </dependency>
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.62</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.17.1</version> </dependency>
-
准备好请求报文文件new_product.json
{
“color”: “#56ABFB”,
“members”: [
“7e7d3bc3fdee474980ac8480b3a01d00”
],
“name”: “测试产品名”,
“identifier”: “CPMSDAAF”,
“description”: “des”
} -
准备feature文件,即测试场景
Feature: TC01_newProduct01
Scenario Outline: Verify the with the payload
Given call the API with data ,
Then check responseCode and responseMessage
Then Check the data in DB
Examples:
| Scenario | Data | responseCode | responseMessage |
| new product Scenario | new_product.json | 200 | successful |
- 实现接口请求发送
@Given(“call the API with data (["]*),([”]*)")
public void get_corp_cus(String scenario, String Data, String messageSource) {
//缺点header,URL,method,然后调用exchang方法发送请求
responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, JSONObject.class);
}