[Introduction to contract testing - Part 2] Contract testing and how Pact works

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 40

  • @PeterZeller1
    @PeterZeller1 2 роки тому +6

    How do you handle state with this approach?
    Like, getting the orders depends on the state of the database, i.e. on the database updates that were done previously.
    Without state, this looks like it's good for type checking only, and I prefer static checks for that.

    • @PactFlow
      @PactFlow  2 роки тому +5

      This is a great question, and is what "Provider States" are designed for. They allow you to setup your system to verify certain API scenarios, without requiring you to coordinate tests to run in a particular order. See docs.pact.io/getting_started/provider_states and our example projects for more.

  • @aofadero
    @aofadero 8 місяців тому

    You mentioned you don't need a dedicated test environment, how would you cater for a hybrid scenario where you want to test an API in a monolith application that also calls a microservice from the provider pov?

  • @صحصحمعالعيال
    @صحصحمعالعيال 6 місяців тому

    does the example mentioned mean that it will test against the provider with order id = 10 ? what it the provider (its SOR actually) doesnt contain and order with this ID? or what if it returns data with values other than the values stored in the repository contract ? is there an option to set these values dynamically so that the values while mock testing the consumer is different than these while testing the real provider ?

    • @PactFlow
      @PactFlow  6 місяців тому +1

      Yes, there are two Pact ways to handle this - the use of Provider States and the use of generators. This is one of the neat ways Pact works around the "data fixture" issue.
      See docs.pact.io/getting_started/terminology#provider-state, docs.pact.io/provider/using_provider_states_effectively and example of dynamic values from the provider here: pactflow.io/blog/injecting-values-from-provider-states/

  • @rosey182
    @rosey182 2 роки тому +1

    Sometimes these terms on testing gets confusing. So what is a unit test to you? I consider unit tests "testing the smallest piece of logic within a class or module ". Whereas a component test is "testing the smallest deployable code possible. A component test should run in its own jvm or container".
    Also does pact test actual live endpoints of an api or just mocked?

    • @PactFlow
      @PactFlow  2 роки тому +1

      Yes, testing terms are confusing :). Strictly speaking, a Pact test on the consumer is closer to an integration test (middle of the pyramid) because we expect the test to also make an http call and crosses a boundary, but it's more helpful to think of it as a unit test in terms of writing a unit test of your code, and allowing it to make the HTTP call. We usually draw in on the boundary of "unit" and "integration" on the classic testing pyramid. On the provider side, it's closer to a component test in your definition.
      A consumer test only uses mocks of the provider, which produces a contract. The contract is then verified against the real provider (usually run locally, not in an integrated environment).
      Hope this helps clarify things!

  • @rahulgiri9880
    @rahulgiri9880 2 роки тому

    1. We still need to deploy the actual Provider to run provider tests. right ? so why we say it is equivalent to unit?
    2. What we do to the Provider dependencies ?

    • @PactFlow
      @PactFlow  2 роки тому

      No, the provider should be tested in a unit test-like context and not in a deployed environment. It should be able to run on your development machine - this is how you get the fast, reliable feedback. Deploying to an environment makes it more of an end-to-end / functional test, which we are trying to avoid with contract testing. This means any dependencies should be stubbed out, and they should then have their own set of Pact tests to ensure they are properly covered also. See docs.pact.io/faq#how-do-i-deal-with-a-situation-where-there-are-multiple-systems-involved-in-a-scenario for more on that.

  • @صحصحمعالعيال
    @صحصحمعالعيال 6 місяців тому

    and can it be used to test non functional and repeatitve tests ... like testing the consumer quota ... CORS options, etc ...

    • @PactFlow
      @PactFlow  6 місяців тому +1

      No, that's not what contract testing is about. See also docs.pact.io/consumer/contract_tests_not_functional_tests

  • @miasanmia4961
    @miasanmia4961 Рік тому

    Hi I am having issues with understanding what to define in the providerstates when creating a interaction via consumer. So it is all good when the domain model in frontend almost has a 1-1 mapping with the backend but it is difficult to understand once the frontend requets a data object that is not pure in the backend but rather build but different sub resources that the frontend (should not and do not want to care about). How should you define providerstates in that case?

    • @PactFlow
      @PactFlow  Рік тому +1

      Think of provider states as a precondition for the consumer test to pass (e.g. "user is authenticated" or "user has a positive credit balance"). The states shouldn't have implementation details in them, it is up to the provider to determine how to implement a provider state handler. The provider could seed a database (if it's a 1:1 mapping) or stub a 3rd party API if it's further downstream.

  • @برنامهنویسارشد
    @برنامهنویسارشد 3 роки тому +2

    Where do we read the contract from? can we read it off proto files?

    •  3 роки тому

      On the first slides it says that a REST/JSON/XML is expected to be checked against. By proto file I assume you mean gRPC which I thinks it’s not supported by Pact. Because it’s a binary response.

    • @PactFlow
      @PactFlow  3 роки тому +1

      We're currently building support for gRPC (via our plugins proposal), so it's coming soon:
      See also:
      * github.com/pactflow/roadmap/projects/1
      * github.com/pact-foundation/pact-specification/issues/83
      * pact.canny.io/feature-requests/p/support-grpc

  • @صحصحمعالعيال
    @صحصحمعالعيال 6 місяців тому

    and is there any way to expedite writing the contract (i.e. test cases) ... because I believe it is a bit verbose

    • @PactFlow
      @PactFlow  6 місяців тому

      Contract testing is more than just ensuring breaking changes. The tests themselves are like any other good test - they apply stress to the design and structure of your code. If Pact tests are hard to write, that is a sign that your code is not very testable and modular and should be improved.
      There are ways to generate tests though, but you should only consider this once you know what you're doing.
      You may also like our bi-directional contract testing feature which simplifies this workflow / allows you to re-use mocks and existing testing tools: docs.pactflow.io/docs/bi-directional-contract-testing

  • @MarkWilson-gc3yq
    @MarkWilson-gc3yq 2 роки тому

    I'm a bit confused with the example given from the provider side.
    Is the Pact verifier checking against the provider or a mocked response from the provider? If so, surely your argument about the other dependant services falls a bit short as the provider is still potentially running against those other services? I can see the value in the consumer side though

    • @MarkWilson-gc3yq
      @MarkWilson-gc3yq 2 роки тому

      Actually I think its nonsense what I've put there.. as at the time this is tested you'd have the consumer up and running as part of the build pipeline right?

    • @PactFlow
      @PactFlow  2 роки тому

      It is recommended to stub out external systems as part of contract testing (see also docs.pact.io/5-minute-getting-started-guide#scope-of-a-provider-pact-test and docs.pact.io/provider#stub-calls-to-downstream-systems). This increases the reliability of those tests and makes them more unit test-like. Of course, if they are other APIs, you should have a separate set of contract tests to cover those, and so on until you reach a leaf node. -Matt

    • @PactFlow
      @PactFlow  2 роки тому

      I'm not sure I understood the second question, but we'd be happy to chat in more detail over at slack.pact.io and clarify any questions you have.
      P.S. you have the voice of an angel 🎶

  • @ricp
    @ricp 3 роки тому

    so, on 6:22 are those Mocks responses mainly stubbed http responses?

    • @PactFlow
      @PactFlow  3 роки тому

      In this case, yes that's correct. For clarity, it's _not_ a stub, it's a mock. A mock is a validated stub. That is, if your code does not call the mock the test fails. This is important, to ensure we're capturing a valid contract.

    • @ricp
      @ricp 3 роки тому

      @@PactFlow thanks for the clarification, i'll read on more to learn about it. I was lookin into it for my company's QA team to use along with Cypress, but it seems this is more suited for a Dev team to use on top of their Unit testing., is that a correct assumption? thanks

    • @PactFlow
      @PactFlow  3 роки тому

      @@ricp Yes that's right. Pact is really designed to be used in a unit test setting (i.e. white-box style testing), when the code is being authored. Pactflow has some features that could be authored external to the code base in a more black-box style test.

  • @Robert-ht5kd
    @Robert-ht5kd 3 роки тому

    How Pact knows what is the correct provider response to consumer request?

    • @PactFlow
      @PactFlow  3 роки тому

      The contract is authored by a human (it's a unit test) and is verified later on by the provider. Check out our introductory videos for how it works.

  • @kals9212
    @kals9212 3 роки тому +1

    What tool is used to draw these diagrams?? Really good

    • @PactFlow
      @PactFlow  3 роки тому +7

      Google slides ;)

  • @glebbash
    @glebbash 3 роки тому +11

    What's that annoying dot? 🤔

  • @Zaicas
    @Zaicas 10 місяців тому

    Well its just a contract testing we can place it in the testing pyramid between unit tests and integration tests and move one - geez

    • @fattymellows
      @fattymellows 10 місяців тому +3

      I'm sorry, is there a point you're trying to make? The video is to help people understand what contract testing is and how it works.

  • @AbbeyLingord
    @AbbeyLingord 3 роки тому +4

    I couldn't finish that video, but the first part it's just nonsense. You are saying to drop integration and e2e tests and do just unit tests (you call it contract, but basically it's just unit tests because use mocking everything). Unit tests go along side integration and e2e, and would never replace it. It's just like you created a new quality control tool to verify car parts quality and you're saying: "Our tool is so good, you don't need assemble car's anymore and test it. We can just sell it, because all parts are tested perfectly already".

    • @PactFlow
      @PactFlow  3 роки тому +4

      Hi Abbey, that's certainly not the intent. Video 1 intends to show the problems with e2e tests, and video 2 is about showing how contract testing works as a mechanism. It's true that contract-testing with Pact uses unit tests on either side of an integration point, they are better than unit tests in terms of guarantees, but less than e2e tests. Contract testing does not cover functional testing, which is another key benefit of e2e tests. Instead of using e2e, we recommend using a combination of tests (functional, contract etc.) and reducing if not removing e2e altogether. See Video 4 where we talk about a more holistic view of a testing strategy. For clarity: contract testing doesn't entirely replace end-to-end tests alone. Hope this helps!
      - Matt

    • @thalibmuhammad9519
      @thalibmuhammad9519 2 роки тому

      thanks, i have same question