如何从合同 json 文件为契约消费者生成模拟服务器?

How to generate mock server for pact consumer from contract json file?

我想使用提供商的合同文件对消费者进行 运行 测试。 我有

{
"provider": {
    "name": "Provider"
},
"consumer": {
    "name": "Consumer"
},
"interactions": [
    {
        "description": "Get data",
        "request": {
            "method": "Get",
            "path": "/data/1"
        },
        "response": {
            "status": 200,
            "headers": {
                "Content-Type": "application/json"
            },
            "body": {
                "message": ""
            }
        },
        "providerState": "state"
    }
],
"metadata": {
    "pact-specification": {
        "version": "2.0.0"
    },
    "pact-jvm": {
        "version": "3.5.6"
    }
}

并想用它来生成协议模拟服务器,例如:

RequestResponsePact pact = new RequestResponsePact(mockServerDescriptionString);

可以这样做吗?

没有。但是您可以使用 pact-stub-server or the pact-stub-service CLI