Skip to content

Commit c0ef69a

Browse files
committed
[add] csvNote.md
1 parent 49183fd commit c0ef69a

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

csvNote.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# csv测试数据相关
2+
> 编写测试数据时,对CSV文件的使用需要遵循一定规则
3+
4+
## Example
5+
6+
ManReq.java
7+
8+
```java
9+
public class ManReq(){
10+
private String name;
11+
private int age;
12+
private Date birth;
13+
//getter and setter
14+
}
15+
```
16+
17+
ManReq.csv表格视图
18+
19+
Man|desc|name|age|birth
20+
:--:|:--:|:--:|:--:|:--:
21+
1 | 正例 | Alice | 20 | 19980408
22+
2 |正例 | Bob | 22 | 19960608
23+
24+
ManReq.csv源文件
25+
26+
```html
27+
ManReq,desc,name,age,birth
28+
1,正例,Alice,20,19980408
29+
2,正例,Bob,22,19960408
30+
```
31+
32+
---
33+
>### 注意事项
34+
35+
1. 行下标从0开始,第0行为表头
36+
37+
2. 表头从第三列开始,其名称必须与对应的Req的field一一对应
38+
3. 在形如`reqList = CSVSupport.getListFromCSV(ManReq.class,
39+
​ ​ "path/ManReq.csv@1-2")`
40+
41+
的使用中,`@1-2`表示数据从第一行取到第二行,若无,则将第0行(表头)忽略,从第1行开始读取到最后一行
42+
43+
```html
44+
其他用法:
45+
ManReq.csv 读取第1至最后一行
46+
47+
ManReq.csv@1 只读取第1行
48+
49+
ManReq.csv@2-4 读取2至4行
50+
51+
ManReq.csv@2:5 读取第2和第5行
52+
53+
ManReq.csv@2:4-6 读取第2行和4至6行
54+
55+
ManReq.csv@2-5:8-10 读取第2至5和第8至10行
56+
```
57+
## 扩展
58+
> 了解如何读取指定行之后,我们就可以往数据中加入更多辅助数据了,比如注释说明
59+
60+
ManReq.csv表格视图,附带注释说明
61+
62+
| Man | desc | name | age | birth |
63+
| :--: | :--: | :---: | :--: | :------: |
64+
| 字段 | 说明 | 姓名 | 年龄 | 生日 |
65+
| Man | 类型 | String | int | String |
66+
| 1 | 正例 | Alice | 20 | 19980408 |
67+
| 2 | 正例 | Bob | 22 | 19960608 |
68+
69+
如上,加了两行辅助行来说明字段意思和数据类型,这时读取数据就要跳过他们,从第3行开始

0 commit comments

Comments
 (0)