SpringCloud契约处理不愉快路径的最佳实践

SpringCloud契约处理不愉快路径的最佳实践,spring,cloud,contract,Spring,Cloud,Contract,我们曾经使用wiremock进行集成测试,有愉快的路径,也有不愉快的路径。现在我们正试图转向基于Spring云契约的集成测试。不过,我找不到任何与不愉快路径的合同相关的文档(状态代码超过400)。作为回应,我做了一些状态代码为4xx/5xx的POC,但它不起作用 有人知道在消费者方面处理不愉快路径的最佳实践吗?或者,对于状态代码超过400且使用spring cloud contract的不愉快路径,它根本不受支持吗?以下是一个示例: 制作人方 Contract.make { descri

我们曾经使用wiremock进行集成测试,有愉快的路径,也有不愉快的路径。现在我们正试图转向基于Spring云契约的集成测试。不过,我找不到任何与不愉快路径的合同相关的文档(状态代码超过400)。作为回应,我做了一些状态代码为4xx/5xx的POC,但它不起作用

有人知道在消费者方面处理不愉快路径的最佳实践吗?或者,对于状态代码超过400且使用spring cloud contract的不愉快路径,它根本不受支持吗?

以下是一个示例:

制作人方

Contract.make {
    description 'get 404 when entity was not found'
    request {
        method GET()
        url '/entities/0'
    }
    response {
        status NOT_FOUND()
    }
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SomeApplication.class)
@AutoConfigureStubRunner(ids = "io.app:entity:+:stubs:8080")
@AutoConfigureTestDatabase
public class EntityClientTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Autowired
    private EntityClient entityClient; // This is a FeignClient

    @Test
    public void shouldThrowNotFoundWithInvalidId() {
        exception.expect(FeignException.class);
        exception.expectMessage("404");

        entityClient.getById(0);
    }
}
客户端

Contract.make {
    description 'get 404 when entity was not found'
    request {
        method GET()
        url '/entities/0'
    }
    response {
        status NOT_FOUND()
    }
}
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SomeApplication.class)
@AutoConfigureStubRunner(ids = "io.app:entity:+:stubs:8080")
@AutoConfigureTestDatabase
public class EntityClientTest {

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Autowired
    private EntityClient entityClient; // This is a FeignClient

    @Test
    public void shouldThrowNotFoundWithInvalidId() {
        exception.expect(FeignException.class);
        exception.expectMessage("404");

        entityClient.getById(0);
    }
}

正如您所看到的,
getById
抛出了一个404,因为合同上这么说。

不快乐的路径与快乐的路径的工作方式非常相同。请记住,来自DSL/MockMvc测试的SpringCloudContract生成WireMock存根的方式与您通过WireMockAPI创建它们的方式非常相同。因此,如果存根说当一些数据被发送到存根中时它将返回400,那么这也应该发生在消费者端。也许你应该把你的样品上传到某个地方,这样我可以试着帮你?