Hi Team, I need some advise on writing contract te...
# general
s
Hi Team, I need some advise on writing contract test for negative (error) scenarios Is it necessary to contract test 5XX error responses ? or only 4XX should be done ? Any guidelines on this? 500 error response would be difficult to setup on provider side, is there a way to achieve that ? or should be mocked on provider side?
y
Always ask does my client care about this type of request I am encoding into a pact file, in your test. If your consumer code makes no distinguish between a 4xx/5xx or just bails on a non 2xx you would probably only want to test for a generic error. If you care a specific response code in your client code, then you can encode it. Otherwise you can just test that your api client doesn’t explode for consumers when it does get a 500, in your regular unit tests. It would maybe be nice if you could choose to exclude pacts from being serialised but still run selective tests, so you could do that functional testing of your consumer using pact as your mock, but without serialising all those cases into the pact and functionally testing the provider
s
okay. How about response header validation? I am new to Pact and contract test so please pardon my basic questions.
y
I would start with reading our pact docs and going through the cicd course and the pact workshop which is available in a few languages. It teaches about basic Pact concepts and moves onto matchers and authorisation
s
sure thanks