我刚刚开始对我的系统采用Pact测试,该系统由一个提供者服务和一个作为用户的Angular前端组成。我成功设置了双方,因此,Angular应用程序生成了一个(单个)pact文件,该文件具有与我的提供程序服务的多个端点的许多交互。在提供程序中,我现在确实面临这样的问题,我的验证测试变得非常大且过于复杂,因为我必须在单个测试中使用所有数据模拟所有端点,例如:]]
@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) } }
还是我的思维有谬误?谢谢。
我刚刚开始对我的系统采用Pact测试,该系统由一个提供者服务和一个作为用户的Angular前端组成。我成功设置了两面,因此,Angular应用程序...
JUnit4自述文件中有关于此主题的部分。我认为这也适用于Junit5 https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-junit#using-multiple-classes-for-the-state-change-methods