moco启动和配置文件使用

这篇文章记录的很详细,我自己简单记录一下
https://www.jianshu.com/p/3ce4ff925528

下载moco-runner-1.1.0-standalone.jar包
地址:https://github.com/wangjm0439/data_help.git

1.单独配置文件
moco-runner-1.1.0-standalone.jar 同目录下新建test.json文件
内容

[
    {
        "description": "首页",
        "request": {
            "uri": "/index",
            "method":"get",
            "queries": {
            "name":"vivi",
            "age":"18"
            
        },
        "response": {
            "text": "hello world"
        }
    }
]

moco 启动命令:
java -Dfile.encoding=UTF-8 -jar moco-runner-1.1.0-standalone.jar http -p 9090 -c test.json

postman 测试请求接口是否有返回


image.png

2.多个配置文件
在moco-runner-1.1.0-standalone.jar 同目录下新建config.json文件
内容:

[
    {"include": "index.json"},
    {"include": "df.json"}
]

在moco-runner-1.1.0-standalone.jar 同目录下新建df.json文件和index.json 文件
df.json 文件内容

[
    {
    "description": "首页",
    "request": {
        "uri": "/df",
        "method": "post"
    },
    "response": {
        "status": 200,
        "headers": {
            "Content-Type": "application/json;charset=UTF-8"
        },

        "json": {
            "respCode": "E0174",
            "respMsg": "交易与原交易不符",
            "version": "1.0.2",
            "mchtId": "ORG07*************089",
            "signType": "RSA",
            "mac": "awU3KKDpHjLmtoP0QoVjEcUyveIfY4EeEapp87SU2Z/ukSdNh6Ydxpigjfn6/c26Nlky3Uq+8lndOyvTb/LjLXBhrAadGnQq11ef8MEzcrqBDM+p5WylIB6L3Xi09cpxzJ+S2zipWn3IKl38cAWWSMn9Z4wSBBgwZJaWiP4QOmE=",
            "serialNo": "2*************000001",
            "stateTime": "20210401150901",
            "traceNo": "3*************003048041"
        }
    }
}
]

index.json文件内容

[
    {
        "description": "首页",
        "request": {
            "uri": "/index",
            "method":"get",
            "queries": {
            "name":"vivi",
            "age":"18"
            
        },
        "response": {
            "text": "hello world"
        }
    }
]

注意:如果请求参数想随便传,不写"queries"内容即可。
启动命令:
java -Dfile.encoding=UTF-8 -jar moco-runner-1.1.0-standalone.jar http -p 9090 -g config.json

postman验证:


image.png
image.png

你可能感兴趣的:(moco启动和配置文件使用)