Skip to content

Commit

Permalink
Merge pull request #2 from sigoden/issue-1
Browse files Browse the repository at this point in the history
Enhancement: Skip, Delay, Retry, Loop, closes #1
  • Loading branch information
sigoden authored Jun 5, 2021
2 parents 504e643 + 15d3409 commit e076edf
Show file tree
Hide file tree
Showing 24 changed files with 1,220 additions and 188 deletions.
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Read this in other languages: [中文](./README.zh-CN.md)
- [CI Support](#ci-support)
- [TDD Support](#tdd-support)
- [User-defined Functions](#user-defined-functions)
- [Skip, Delay, Retry, Loop](#skip-delay-retry-loop)
- [Annotation](#annotation)
- [Entrypoint Annotation](#entrypoint-annotation)
- [Test Case Annotation](#test-case-annotation)
Expand Down Expand Up @@ -361,6 +362,116 @@ Use functions
}
```

### Skip, Delay, Retry, Loop

In some scenarios, use cases may not need to be executed, or they may need to be executed repeatedly. It is necessary to add a `run` option to support this feature.

#### Skip

```
{
test1: { @client("echo")
req: {
},
run: {
skip: `mod1.test1.res.status === 200`, @eval
}
}
}
```

- `run.skip` skip the test when true

#### Delay

Run the test case after waiting for a period of time

```
{
test1: { @client("echo")
req: {
},
run: {
delay: 1000,
}
}
}
```

- `run.delay` delay in ms

#### Retry

```
{
test1: { @client("echo")
req: {
},
run: {
retry: {
stop:'$run.count > 2', @eval
delay: 1000,
}
},
}
}
```

variables:
- `$run.count` records the number of retries.

options:
- `run.retry.stop` whether to stop retry
- `run.retry.delay` interval between each retry (ms)

#### Loop

```
{
test1: { @client("echo")
req: {
v1:'$run.index', @eval
v2:'$run.item', @eval
},
run: {
loop: {
delay: 1000,
items: [
'a',
'b',
'c',
]
}
},
}
}
```

variables:
- `$run.item` current loop data
- `$run.index` current loop data index

options:
- `run.loop.items` iter pass to `$run.item`
- `run.loop.delay` interval between each cycle (ms)

#### dump

```
{
test1: { @client("echo")
req: {
},
run: {
dump: true,
}
}
}
```

- `run.dump` force print req/res data when true


## Annotation

Apitest uses JSONA format to describe test cases.
Expand Down
111 changes: 111 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Apitest 是一款使用类JSON的DSL编写测试用例的自动化测试工具
- [支持CI](#支持ci)
- [支持TDD](#支持tdd)
- [用户定义函数](#用户定义函数)
- [跳过,延时,重试与循环](#跳过延时重试与循环)
- [注解](#注解)
- [入口文件注解](#入口文件注解)
- [用例注解](#用例注解)
Expand Down Expand Up @@ -362,6 +363,116 @@ function isDate(date) {
}
```

### 跳过,延时,重试与循环

在某些场景中,用例可能不需要执行,可能需要失败重试,可能需要重复执行。

#### 跳过

```
{
test1: { @client("echo")
req: {
},
run: {
skip: `mod1.test1.res.status === 200`, @eval
}
}
}
```

- `run.skip` 值为true时跳过测试

#### 延时

等待一段时间后再执行测试用例

```
{
test1: { @client("echo")
req: {
},
run: {
delay: 1000,
}
}
}
```

- `run.delay` 等待时间

#### 重试

```
{
test1: { @client("echo")
req: {
},
run: {
retry: {
stop:'$run.count> 2', @eval
delay: 1000,
}
},
}
}
```

变量
- `$run.count` 当前重试次数

配置
- `run.retry.stop` 为true时退出重试
- `run.retry.delay` 重试间隔时间

#### 循环

```
{
test1: { @client("echo")
req: {
v1:'$run.index', @eval
v2:'$run.item', @eval
},
run: {
loop: {
delay: 1000,
items: [
'a',
'b',
'c',
]
}
},
}
}
```

变量
- `$run.item` 当前循环数据
- `$run.index` 当前循环数据索引,也可以当成次数

配置
- `run.loop.items` 循环数据
- `run.loop.delay` 循环时间间隔


#### 打印控制

```
{
test1: { @client("echo")
req: {
},
run: {
dump: true,
}
}
}
```

- `run.dump` 为true时强制打印请求响应数据

## 注解

Apitest 使用JSONA格式描述测试用例。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dev": "ts-node src/bin.ts",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist",
"test": "jest",
"test": "yarn build && jest",
"prepublish": "npm run -s clean && npm run -s build"
},
"dependencies": {
Expand Down
Loading

0 comments on commit e076edf

Please sign in to comment.