Skip to content

Commit 4443a51

Browse files
author
徐平
committed
常量引用,添加代码注释,准备开放源码;
1 parent 4d3acf5 commit 4443a51

File tree

22 files changed

+162
-104
lines changed

22 files changed

+162
-104
lines changed

ReadMe.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
#### eclipse创建SpringBoot项目
2-
- 没有找到支持快速创建SpringBoot项目的STS插件
3-
- 使用了lombok插件,免去字段的setter和getter方法
4-
- 使用了generate setter插件,创建参数对象,支持alt+enter选择批量生成类的所有setter方法
5-
- 使用比较熟悉的testng框架做单元测试
6-
- 添加了swagger依赖,支持UI接口文档
7-
- - 配置swaggerconfig类
8-
9-
#### 如何配置swagger接口文档
10-
- application.yml配置是否开启swagger开关
11-
- yml配置文件格式,:值后面必须空格,否则不生效
12-
- 在启动application项目时加上@EnableSwagger2注解
13-
- - 在swaggerconfig配置了controller类前有@Api注解的类,在每个接口有@ApiOperation注解的方法
14-
15-
#### springboot快速写生成mock
16-
- 主要用于解决接口依赖,快速进行接口测试
17-
- 也可以使用json对象的字符串形式,再以json对象返回
18-
- - 如果在Result类中有Map集合可以使用Map对象返回
19-
- pom文件写入的依赖,需要停止application重新在启用
20-
21-
22-
#### HTTP请求方法介绍
23-
- @PostMapping post请求
24-
- - 有参数,可以在方法里使用:method(@RequestBody paramType param):
25-
- - post请求可以看做是map集合,可以使用getparam获取请求的参数:param.getParam()
26-
- - 也可以@RequestParam获取请求的非json的数据
27-
- @GetMapping(value="/api/{id}") get请求
28-
- - @PathVariable注解可以直接获取接口地址后面拼接的变量:method(@PathVariable("id") int id)
29-
- - @RequestParam注解是自定义组装拼接的参数
30-
- @RequestMethod 如果不指定请求方法:method = RequestMethod.GET,它会支持所有http请求的方法
31-
- - 如果有参数,可以在方法里(@RequestParam(""))
1+
#### eclipse创建SpringBoot项目
2+
- 没有找到支持快速创建SpringBoot项目的STS插件
3+
- 使用了lombok插件,免去字段的setter和getter方法
4+
- 使用了generate setter插件,创建参数对象,支持alt+enter选择批量生成类的所有setter方法
5+
- 使用比较熟悉的testng框架做单元测试
6+
- 添加了swagger依赖,支持UI接口文档
7+
- - 配置swaggerconfig类
8+
9+
#### 如何配置swagger接口文档
10+
- application.yml配置是否开启swagger开关
11+
- yml配置文件格式,:值后面必须空格,否则不生效
12+
- 在启动application项目时加上@EnableSwagger2注解
13+
- - 在swaggerconfig配置了controller类前有@Api注解的类,在每个接口有@ApiOperation注解的方法
14+
15+
#### springboot快速写生成mock
16+
- 主要用于解决接口依赖,快速进行接口测试
17+
- 也可以使用json对象的字符串形式,再以json对象返回
18+
- - 如果在Result类中有Map集合可以使用Map对象返回
19+
- pom文件写入的依赖,需要停止application重新在启用
20+
21+
22+
#### HTTP请求方法介绍
23+
- @PostMapping post请求
24+
- - 有参数,可以在方法里使用:method(@RequestBody paramType param):
25+
- - post请求可以看做是map集合,可以使用getparam获取请求的参数:param.getParam()
26+
- - 也可以@RequestParam获取请求的非json的数据
27+
- @GetMapping(value="/api/{id}") get请求
28+
- - @PathVariable注解可以直接获取接口地址后面拼接的变量:method(@PathVariable("id") int id)
29+
- - @RequestParam注解是自定义组装拼接的参数
30+
- @RequestMethod 如果不指定请求方法:method = RequestMethod.GET,它会支持所有http请求的方法
31+
- - 如果有参数,可以在方法里(@RequestParam(""))
32+
33+
#### @DataProvider注解
34+
- 在接口测试框架中,通过注解,从csv、excel、mysql读取数据驱动接口测试

src/main/boot/com/xp/test/base/Application.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5-
import org.springframework.test.context.ActiveProfiles;
65

76
import springfox.documentation.swagger2.annotations.EnableSwagger2;
87

src/main/java/com/xp/test/base/client/RestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public CloseableHttpResponse sendGet(String url,
166166
}
167167

168168
/**
169-
* 封装post方法
169+
* 封装带请求头的post方法
170170
*
171171
* @param url
172172
* @param entityString

src/main/java/com/xp/test/common/config/BasicConfig.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
public class BasicConfig {
1313

1414
public static Properties prop;
15+
// 这些常量数据,可以提取出去
1516
public int RESPNSE_STATUS_CODE_200 = 200;
1617
public int RESPNSE_STATUS_CODE_201 = 201;
1718
public int RESPNSE_STATUS_CODE_404 = 404;
1819
public int RESPNSE_STATUS_CODE_500 = 500;
1920

20-
// 写一个构造函数,读取配置文件
21+
// 构造函数,读取配置文件
2122
public BasicConfig() {
2223

2324
try {
2425
prop = new Properties();
2526
FileInputStream fis = new FileInputStream(
26-
System.getProperty("user.dir")+ "/src/test/resources/config.properties");
27-
28-
System.out.println(System.getProperty("user.dir")+ "/src/test/resources/config.properties");
27+
System.getProperty("user.dir")
28+
+ "/src/test/resources/config.properties");
29+
2930
prop.load(fis);
30-
// 使用Exception 类集合,去掉了IOException、FileNotFoundException异常
31+
// 使用Exception 类集合,去掉了IOException、FileNotFoundException异常
3132
} catch (Exception e) {
3233
e.printStackTrace();
3334
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.xp.test.common.constant;
2+
3+
public class Constants {
4+
5+
public int RESPNSE_STATUS_CODE_200 = 200;
6+
public int RESPNSE_STATUS_CODE_201 = 201;
7+
public int RESPNSE_STATUS_CODE_404 = 404;
8+
public int RESPNSE_STATUS_CODE_500 = 500;
9+
10+
String DIRPATH="/src/test/resources/config.properties";
11+
}

src/main/java/com/xp/test/common/param/Users.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.xp.test.common.param;
22

33
/**
4-
* 一些http接口请求的参数封装 根据接口名称来设置成员变量
4+
* 一些http接口请求的参数封装 根据接口名称来设置成员变量 其他接口,可以仿照如此设计
55
*
66
* @author qguan
77
*

src/main/java/com/xp/test/common/utils/HandleCsvUtils.java

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ public static Object[][] getDatasByCSV(String filePath) throws IOException {
7070
",(?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
7171

7272
for (int i = 0; i < fields.length; i++) {
73-
// 处理之后的单元格数据重新写入一维数组
74-
System.out.println(fields[i]);
75-
// fields[i] = fields[i].replaceAll("^\"",
76-
// "").replaceAll("\"$","");
73+
// 处理之后的单元格数据重新写入一维数组;去掉收尾双引号
74+
fields[i] = fields[i].replaceAll("^\"", "").replaceAll("\"$",
75+
"");
7776
}
7877

7978
records.add(fields);
@@ -91,19 +90,28 @@ public static Object[][] getDatasByCSV(String filePath) throws IOException {
9190
return results;
9291
}
9392

93+
/**
94+
* CsvReader这个工具类的使用,但是需要内部消化 转成Object[][]二维数组提供testng数据源
95+
*
96+
* @param filePath
97+
* @return
98+
* @throws Exception
99+
*/
94100
public static ArrayList<String[]> readCSV(String filePath) throws Exception {
95101
CsvReader reader = null;
96102
ArrayList<String[]> dataList = new ArrayList<String[]>();
97-
103+
98104
try {
99105
// 如果生产文件乱码,windows下用gbk,linux用UTF-8
100-
reader = new CsvReader(filePath, separator, Charset.forName("utf-8"));
106+
reader = new CsvReader(filePath, separator,
107+
Charset.forName("utf-8"));
101108

102109
// 读取表头
103110
reader.readHeaders();
104-
111+
105112
String[] headArray = reader.getHeaders();// 获取标题
106-
System.out.println("我是"+headArray[0] + headArray[1] + headArray[2]);
113+
System.out.println("我是" + headArray[0] + headArray[1]
114+
+ headArray[2]);
107115

108116
} catch (Exception e) {
109117
e.printStackTrace();
@@ -116,20 +124,4 @@ public static ArrayList<String[]> readCSV(String filePath) throws Exception {
116124
return dataList;
117125
}
118126

119-
public static void main(String[] args) throws Exception {
120-
String destFile = "D:\\javaworkspace\\springbootSwagger\\src\\test\\resources\\test.csv";
121-
Object[][] ob = HandleCsvUtils.getDatasByCSV(destFile);
122-
123-
for (int i = 0; i < ob.length; i++) {
124-
for (int j = 0; j < ob[i].length; j++) {
125-
System.out.println(ob[i][j]);
126-
}
127-
128-
}
129-
List<String[]> res = HandleCsvUtils.readCSV(destFile);
130-
131-
for (int i = 0; i < res.size(); i++) {
132-
System.out.println(res.get(i));
133-
}
134-
}
135127
}

src/main/java/com/xp/test/common/utils/HandleMySQLUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ public static Connection connectMySQL(String url, String user, String passwd) {
4242
}
4343

4444
/**
45-
* default 创建数据库连接
45+
* default 创建数据库连接 修改数据
4646
*
4747
* @return
4848
* @throws SQLException
4949
* @throws ClassNotFoundException
5050
*/
5151
public static Connection connectMySQL() {
52-
String url = "jdbc:mysql://47.107.254.16:3306/mysql?useSSL=false";// prop.getProperty("MYSQLHOST");
52+
String url = "jdbc:mysql://192.107.254.161:3306/mysql?useSSL=false";// prop.getProperty("MYSQLHOST");
5353
String userName = "root";// prop.getProperty("MYSQLUSER");
54-
String password = "Hcp_dev_0326";// prop.getProperty("MYSQLPASSWD");
54+
String password = "";// prop.getProperty("MYSQLPASSWD");
5555
try {
5656
Class.forName("com.mysql.cj.jdbc.Driver");
5757
conn = DriverManager.getConnection(url, userName, password);

src/main/java/com/xp/test/common/utils/HandleParamUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
/**
1616
* 公用替换参数的类,其中封装了参数替换的方法,不定长传参转list
1717
*
18+
* 这个类本来是提供给jmeter做接口自动化使用
19+
*
1820
* @author Administrator
1921
*
2022
*/

src/main/java/com/xp/test/common/utils/JSONExtractor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/**
1010
* 封装JSON格式数据提取方法
1111
*
12+
* 这个工具类也是为了提供给jmeter做接口自动化测试的
13+
*
1214
* @author qguan
1315
*
1416
*/

0 commit comments

Comments
 (0)