我刚刚开始对我的系统采用 Pact 测试,该系统由一个提供者服务和一个作为消费者的 Angular 前端组成。我成功地设置了双方,因此,Angular 应用程序生成了一个(单个)协议文件,其中包含与我的提供程序服务的多个端点的许多交互。在提供者中,我现在确实面临验证测试变得非常大且过于复杂的问题,因为我必须在一个测试中使用它们的所有数据模拟所有端点,例如:
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class ComprehensivePactTest {
[...]
@State("healthy")
fun `healthy state`() {
whenever(exampleService.dosomething(any())).thenReturn(exampleResponse)
whenever(otherService.somethingElse()).thenReturn(otherResponse)
}
}
有没有办法将交互与协议文件分开,以便我可以在我的提供程序中进行多个小型验证测试?例如,我想对路径以“/example”开头的所有请求进行验证测试,并对以“/other”开头的路径进行第二次测试。
所以我更喜欢像这样更小、更集中的验证测试:
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class ExampleEndpointPactTest {
[... include some filter logic here ...]
@State("healthy")
fun `healthy state`() {
whenever(exampleService.dosomething(any())).thenReturn(exampleResponse)
}
}
@Provider("example-backend")
@PactFolder("pacts")
@SpringBootTest(...)
class OtherEndpointPactTest {
[... include some filter logic here ...]
@State("healthy")
fun `healthy state`() {
whenever(otherService.somethingElse()).thenReturn(otherResponse)
}
}
还是我的想法有谬误?谢谢。