Code Monkey home page Code Monkey logo

apicrawler's Introduction

apiCrawler

特色

  • 使用Junit5 + Rest Assured + Hamcrest + Allure搭建框架
  • 以yaml格式定义测试用例模板,实现数据驱动
  • 测试用例支持使用“${XX}”格式来代表变量,执行前被替换成对应的值
  • 将常用的测试用例变成单元,不可直接执行,但可在测试步骤中多处调用,避免测试用例重复描述
  • 支持variables/extract/validate机制,创建复杂的测试用例
  • 使用jsonPath来提取和验证json响应体

名词解释

  • 测试用例单元(TestCase)是一个最小化的接口定义,不能单独执行,需要嵌套在测试步骤内。
  • 测试步骤(TestStep)可引用测试用例单元,是一个完整的接口请求响应。
  • 测试用例集(TestStepModel)的测试步骤序列是测试步骤(TestStep)的有序集合,测试步骤有顺序或者依赖关系。
  • 测试用例集(TestStepModel)之间是无序,形成测试场景,在ApiTest中使用Junit5的测试参数执行。

目录结构

src
├── test
│    ├── java
│    	    ├── pageObject
│          	    ├── ApiTest
│          	    ├── Config
│          	    ├── Parameters
│          	    ├── Request
│          	    ├── Restful
│         	    ├── TestCase
│         	    ├── TestCaseProcess
│          	    ├── TestStep
│          	    ├── TestStepModel
│          	    ├── Validate
│    	    ├── util
│          	    ├── function
├── ── resources
│    ├── pageObject
│    	    ├── config
│          	    ├── gloabl.yaml
│    	    ├── module
│          	    ├── testcaseA.yaml

变量

1. Request

  • String url
  • String method
  • Map<String, Object> headers
  • Map<String, Object> json
  • Map<String, Object> query

2. Config

  • String name
  • Map<String, Object> variables

3. TestCase

  • String name
  • Request request
  • List export
  • Map<String, String> extract
  • Map<String, Map<String, Object>> validate

4. TestStep

  • String name
  • Map<String, Object> variables
  • String testcase

5. TestStepModel

  • Config config
  • List testSteps

核心代码

void toRunStep() {
        loadTestCase();//加载测试用例
        replaceVariables();//替换testcase和config里变量
        replaceHeaders();//替换headers里的变量
        replaceJson();//替换body的json变量
        replaceQuery();//替换body的query变量
        run();//运行并保存变量
        validate();//断言
    }

yaml例子

config:
    name: testsuite名字
testSteps:
    -
        name: testStep1名字
        request:
            url: api
            method: get
            headers:
                token: ${token}
                user-agent: ${user-agent}
        extract:    
            paramName: "jsonPath规则提取参数"
        export: [ "paramName"]
    -
        name: testStep2名字
        variables:
            currentPage: 1
            fenceId: ${paramName}
        testcase: "testcase路径"  
        validate:
            greaterThan:
                cartId: ["Integer", 0]

apicrawler's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.