【发布时间】:2018-08-23 04:04:43
【问题描述】:
契约消费者是否测试生成合约 json 文件?
我正在研究协议并且对消费者测试的目的感到好奇?它测试测试类定义的响应。
在我下面的代码中。我用 200 和简单的正文定义了一个响应,然后通过 mockProvider 调用测试它。似乎没用。有人请给我一些指导。
public class PactTest {
@Rule
public PactProviderRuleMk2 mockProvider
= new PactProviderRuleMk2("test-provider", "localhost", 8017, this);
@Pact(consumer = "test-consumer")
public RequestResponsePact createPact(PactDslWithProvider builder){
Map<String, String> headers = new HashMap<>();
return builder
.given("test Get")
.uponReceiving("GET REQUEST")
.path("/pact")
.method("GET")
.willRespondWith()
.status(200)
.headers(headers)
.body("{\"condition\": true, \"name\":\"tom\"}")
.toPact();
}
@Test
@PactVerification
public void givenGet_whenSendRequest_shouldReturn200withProperHeaderAndBody() {
ResponseEntity<String> res = new RestTemplate()
.getForEntity(mockProvider.getUrl()+"/pact", String.class);
assertThat(res.getStatusCode().value()).isEqualTo(200);
}
}
【问题讨论】:
标签: testing microservices pact