question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Questions - Contract tests vs functional tests

See original GitHub issue

Hello

We are still evaluating Pact tests in our organisation and have so far written consumer and provider tests, thanks mostly to tdshipleyā€™s pact workshop in .NET Core. (Also thanks to you guys for pact-net!)

Iā€™m still struggling to get my head around the Pact tests and what value they provide. I feel like Iā€™m missing something. Now that we have a working implementation I have a few questions, if I may.

  1. The best practices over at pact.io has this specific example https://docs.pact.io/best_practices/consumer/contract_tests_not_functional_tests
Given that username "bad_username" is invalid
When "creating a user with an invalid username"
  POST /users { "username": "bad_username", ... }
Then
  Response is 400 Bad Request
  Response body is { "error": "<any string>" }

I canā€™t see how the provider-state API middleware could accomplish this sort of setup. Maybe the ProviderStateMiddleware would need to live in my API under test instead of in a separate provider state API, but even then I donā€™t think it would be possible. 2. According to https://docs.pact.io/readme

Pact tests should be data independent. Pact tests are best when successful verification doesnā€™t depend on the specific data that the provider returns.

So letā€™s say I have a CRUD app which returns a 201 and the ID of the created entity when I POST to it. My consumer tests just need to check that an ID is returned, and that itā€™s a GUID. They donā€™t care what the ID is. My provider tests need to confirm that they return a GUID too. What would that look like in my pact.json? How about:

      "response": {
        "status": 201,
        "headers": {
          "Content-Type": "application/json; charset=utf-8"
        },
        "body": {
          "id": "b106887d-7edb-47fd-a1e8-fbe0abdd84b6"
        }
      }

This seems wrong, since Iā€™m tying my test to a specific id. And how would I set that up with provider state?

Any clarification appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bethesquecommented, Aug 30, 2018

@mattfrear I think that is just a poorly worded example. There is nothing in a provider state that would generally change the way that the validation was implemented (unless there was something like a length that could be configured). Iā€™ll see about updating that.

0reactions
mattfrearcommented, Sep 6, 2018

Thanks @bethesque , yes thatā€™s much better šŸ‘

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contract Tests vs Functional Tests | Pact Docs
Contract tests focus on the messages that flow between a consumer and provider, while functional tests also ensure that the correct side effectsĀ ......
Read more >
What's the difference between integration and contract ...
Contract tests focus on the messages that flow between a consumer and provider, while functional tests also ensure that the correct side effectsĀ ......
Read more >
End-to-end vs. contract-based testing: How to choose
One of the arguments against contract-based testing is that it doesn't cover the full functionality and only scratches the surface. Following full functionalĀ ......
Read more >
Contract Testing Tutorial: Comprehensive Guide With Best ...
Contract tests stresses the communications between a consumer and a provider, while functional tests verify that the intended side effects have taken place....
Read more >
Accelerating Releases with Quality: Contract Testing vs. ...
While contract testing focuses on the contract of each single endpoint, functional testing makes sure that the API consumer can fully supportĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found