Questions - Contract tests vs functional tests
See original GitHub issueHello
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.
- 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:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@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.
Thanks @bethesque , yes thatās much better š