new feature: testcases can be layered, now we can define interface in api block individually

This commit is contained in:
debugtalk
2017-09-18 15:21:50 +08:00
parent 479f0e5860
commit cd20b0a8dc
8 changed files with 179 additions and 6 deletions

26
tests/data/api.yml Normal file
View File

@@ -0,0 +1,26 @@
- api:
def: get_token($user_name, $device_sn, $os_platform, $app_version)
request:
url: /api/get-token
method: POST
headers:
user_agent: $user_agent
device_sn: $device_sn
os_platform: $os_platform
app_version: $app_version
json:
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
validators:
- {"check": "status_code", "comparator": "eq", "expected": 200}
- {"check": "content.token", "comparator": "len_eq", "expected": 16}
- api:
def: create_user($uid, $user_name, $user_password, $token)
request:
url: /api/users/$uid
method: POST
headers:
token: $token
json:
name: $user_name
password: $user_password

View File

@@ -0,0 +1,40 @@
- config:
name: "create user testsets."
variable_binds:
- user_agent: 'iOS/10.3'
- device_sn: ${gen_random_string(15)}
- os_platform: 'ios'
- app_version: '2.8.6'
request:
base_url: $BASE_URL
headers:
Content-Type: application/json
device_sn: $device_sn
- test:
name: get token
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
extract_binds:
- token: content.token
- test:
name: create user which does not exist
variable_binds:
- uid: 1000
- user_name: "user1"
- user_password: "123456"
api: create_user($uid, $user_name, $user_password, $token)
validators:
- {"check": "status_code", "comparator": "eq", "expected": 201}
- {"check": "content.success", "comparator": "eq", "expected": true}
- test:
name: create user which does not exist
variable_binds:
- uid: 1000
- user_name: "user1"
- user_password: "123456"
api: create_user($uid, $user_name, $user_password, $token)
validators:
- {"check": "status_code", "comparator": "eq", "expected": 500}
- {"check": "content.success", "comparator": "eq", "expected": false}