0

我正在尝试在本地设置 pact python 项目并面临问题。如果你能在这些问题上帮助我,那就太好了

看来我们必须从消费者端使用 localhost:1234 ?. 我们可以使用真实服务代替模拟服务吗?如果我使用 localhost:1234 ,则生成了协议,但是如果我使用真实服务,则会出现错误 所以我的问题是,当我们从消费者方面创建协议时,我们是否需要始终使用 Mock 服务((本地主机:1234)

第二个问题:我来自 QA 团队,认为协议应该由 DEV 团队而不是 QA 团队编写。我的假设正确吗?如果是,这些协议将如何帮助 QA 团队?

消费者.py

    import requests
    def callAPI(self,inputString,Url):
    respone = requests.get(url+inputString).status_code

test_consumer.py:

 pact = Consumer ( 'consumer' ).has_pact_with ( Provider ( 'provider' ) )
      pact.start_service ()
      atexit.register ( pact.stop_service )


      def test_callAPI (self):
      url = 'http://localhost:1234'

      pact.given ( 'sending user name to Url'
                 ).upon_receiving (
        'once i get the respone from service'
      ).with_request (
        'get', '/' ).will_respond_with ( 200)

     with pact:
        result = callAPI (url)
        self.assertEqual ( result['status_code'], 200 )

先感谢您,

4

1 回答 1

1

Yes, your code must hit the mock server else we can't be sure what you're expecting is actually true. Contract testing uses this to guarantee it's requirements on a provider.

You can also tell Pact to use any port, that's just the default.

should devs write them ... how will it help the QA team?

Well the short answer is yes, they really should be written by those writing the code. Is that a bad thing? As a QA I would imagine this makes your job easier as quality is automatically higher and you can focus on more important activities instead of writing automation tests.

于 2018-07-28T00:26:48.483 回答