Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

需求: 测试用例的增量断言 #1142

Open
zhengtong0898 opened this issue Jan 9, 2022 · 0 comments
Open

需求: 测试用例的增量断言 #1142

zhengtong0898 opened this issue Jan 9, 2022 · 0 comments
Assignees
Labels
pending pending for confirmation

Comments

@zhengtong0898
Copy link

背景描述

分层机制强调定义好一个API用例后交给另外一个用例来引用,而不是每个用例都全部再写一遍。

为了能让API用例满足不同的场景,需要在早期就尽可能的对API用例考虑周全并设计足够通用的能力。
比如说要预留足够多的断言变量,向上暴露足够多的响应数据,场景举例:

登录接口用例设计:
站在API用例的角度来讲,它其实不应该关心断言,
但是为了足够通用,这里就需要设计一些变量来传递给validate来完成断言.

login-api.yml

config:
    name: "module variable"
    desc: "这里定义的是当前API要求必填的参数"
    variables:
        host: ""
        username: ""
        password: ""
        status_code: ""
        body_status: ""
        body_msg: ""


teststeps:
-
    name: login
    request:
        method: POST
        url: "${host}/login"
        headers:
            User-Agent: HttpRunner/${get_httprunner_version()}
            Content-Type: "application/x-www-form-urlencoded"
        data: "username=${username}&password=${password}"
    validate:
        - eq: ["status_code", "${status_code}"]
        - eq: ["body.status", "${body_status}"]
        - eq: ["body.msg", "${body_msg}"]

 

期望的功能特性

如果能对API用例进行扩展断言,那么就意味着可以对场景进行封装,例如: 将登录接口封装成登录成功场景登录失败场景

login-api.yml

config:
    name: "module variable"
    desc: "这里定义的是当前API要求必填的参数"
    variables:
        host: ""
        username: ""
        password: ""


teststeps:
-
    name: login
    request:
        method: POST
        url: "${host}/login"
        headers:
            User-Agent: HttpRunner/${get_httprunner_version()}
            Content-Type: "application/x-www-form-urlencoded"
        data: "username=${username}&password=${password}"

 
login-success.yml

config:
    name: "module variable"


teststeps:
-
    name: login
    testcase: apis/login-api.yml
    variables:
        host: "http://127.0.0.1:8888"
        username: "zhangsan"
        password: "zhangsan123"
    validate:
        - eq: ["status_code", 200]
        - eq: ["body.status", 200]
        - eq: ["body.msg", "login success"]

 
login-fail.yml

config:
    name: "module variable"


teststeps:
-
    name: login
    testcase: apis/login-api.yml
    variables:
        host: "http://127.0.0.1:8888"
        username: "zhangsan"
        password: "lisi123"
    validate:
        - eq: ["status_code", 200]
        - eq: ["body.status", 400]
        - eq: ["body.msg", "login failed"]

通过这种扩展方式,在后续写用例中只对登录成功登录失败进行引用。

@zhengtong0898 zhengtong0898 added the pending pending for confirmation label Jan 9, 2022
zhengtong0898 added a commit to zhengtong0898/httprunner that referenced this issue Jan 9, 2022
@zhengtong0898 zhengtong0898 changed the title 测试用例的增量断言 需求: 测试用例的增量断言 Jan 13, 2022
zhengtong0898 added a commit to zhengtong0898/httprunner that referenced this issue Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending pending for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants