Skip to content

【自荐工具】 Apitest —使用类JSON的DSL编写测试用例的自动化测试工具 #1788

@sigoden

Description

@sigoden

源码

github.com/sigoden/apitest

特性

  • 类JSON的DSL编写用例
  • 跨平台,跨编程语言
  • 支持Mock
  • 数据即断言
  • 数据即变量
  • 支持Mixin
  • 支持CI
  • 支持TDD
  • 用户定义函数

快速开始

编写测试文件 httpbin.jsona

{
  test1: {
    req: {
      url: "https://httpbin.org/post",
      method: "post",
      header: {
        'content-type': 'application/json',
      },
      body: {
        v1: "bar1",
        v2: "Bar2",
      },
    },
    res: {
      status: 200,
      body: { @partial
        json: {
          v1: "bar1",
          v2: "bar2"
        }
      }
    }
  }
}

运行测试

apitest httpbin.jsona

module main
  unit test1 (0.944) ✘
  main.test1.res.body.json.v2: bar2 ≠ Bar2

  ...

用例测试失败,从Apitest打印的错误信息中可以看到, main.test1.res.body.json.v2 的实际值是 Bar2 而不是 bar2

我们修改 bar2Bar2 后,再次执行 Apitest

apitest httpbin.jsona

module main
  unit test1 (0.930) ✔

这次测试通过了。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions