gpt4 book ai didi

gradle - PACT 的提供方使用 gradle

转载 作者:行者123 更新时间:2023-12-03 05:48:45 28 4
gpt4 key购买 nike

我是 PACT 的新手。我的应用程序是一个 Spring 启动应用程序。消费者在 PACT 代理中创建了协议(protocol)。现在我正在尝试从提供者端运行测试,并且我正在使用 gradle 插件来运行测试。我有几个问题:

  • 消费者发布的协议(protocol)没有指定任何状态。所以这意味着我不必在提供者端使用任何 stateChangeUrl 吗?
  • 已发布的 Pact 具有 get 方法。但是,当我运行 pactVerify 服务器启动并且我的 pact 测试失败时,因为我没有任何现有数据。之后如何注入(inject)数据。

  • 我想要实现的是:当我说 pactVerify
  • 服务器启动,我的 Spring Boot 应用程序应该在 localhost 中启动并运行(这很好)
  • 在验证协议(protocol)之前,我需要注入(inject)一些数据,例如“POST\add User。这样当它尝试执行 GET\User 时,协议(protocol)测试就会通过。(如何做到这一点?)

  • 下面是我的gradle文件
    pact {
    serviceProviders {
    'user-api' {
    protocol = 'http'
    host = 'localhost'
    port = 8080

    startProviderTask = startService
    terminateProviderTask = stopService

    if ('pactVerify' in gradle.startParameter.taskNames) {
    hasPactsFromPactBroker('http://pactbroker.com') {
    < How to write some code here to say do POST before running PACT >

    }

    }

    }
    }

    最佳答案

    1. Pact published by consumer do not have any states specified. So this means I don't have to use any stateChangeUrl at provider side ?


    这意味着您已选择不使用此机制来更改状态,因此是的,您不需要使用该 URL。但你可能希望改变主意。

    1. Pact published has get method. However when I run pactVerify server starts and my pact tests are failing because I don't have any existing data. How can I inject data after.


    为什么不在开始所有测试之前注入(inject)数据?如果您没有需要担心的状态,那么您也可以使用预加载到数据库中的数据来启动提供程序。

    如前所述,所有配置信息都可以在 https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-gradle 找到。 .

    关于gradle - PACT 的提供方使用 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48819679/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com