如何使用 @PactTestFor 定义多个提供者

huangapple go评论69阅读模式
英文:

How to define multiple providers using @PactTestFor

问题

我们正在使用 PACT 库进行契约测试。当前项目依赖于 junit5 集成。我必须扩展一个测试,以使用两个提供者而不是一个:

当前版本:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    public void myTestMethod() throws Exception {}

我阅读了文档:https://docs.pact.io/implementation_guides/jvm/consumer/junit5,看起来目前还不支持:
>不支持#
>
>当前实现不支持具有多个提供者的测试。这将在以后的版本中添加。

我查看了发布说明,但没有找到任何更新。是否有其他方法来定义另一个提供者?例如像这样的内容:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    @PactTestFor(providerName = "result-repository", hostInterface = "0.0.0.0", port = "9992")
    public void myTestMethod() throws Exception {}

或者在这种情况下,junit5 集成不是一个好的选择?

英文:

We are using PACT library for contract testing. Current project relies on junit5 integration. I have to extend one test to use 2 providers instead of 1:

Current version:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    public void myTestMethod() throws Exception {}

I read doc: https://docs.pact.io/implementation_guides/jvm/consumer/junit5 and it seems to be not supported yet:
>Unsupported#
>
>The current implementation does not support tests with multiple providers. This will be added in a later release.

I checked the release notes and I haven't found any updates. Is there another way how to define another provider? ie something as:

    @Test
    @PactTestFor(providerName = "request-repository", hostInterface = "0.0.0.0", port = "9991")
    @PactTestFor(providerName = "result-repository", hostInterface = "0.0.0.0", port = "9992")
    public void myTestMethod() throws Exception {}

Or in this case junit5 integration is not a good choice?

答案1

得分: 2

我的建议是编写两个单独的测试,每个测试都通过 Pact 对一个提供者进行模拟,而将另一个提供者进行桩测试(例如,使用标准单元测试桩)。

英文:

My suggestion would be to write 2 separate tests, where each test has one provider mocked via Pact and the other provider stubbed out (e.g. with a standard unit test stub).

huangapple
  • 本文由 发表于 2020年10月21日 16:08:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64459294.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定