Hi there, I am new to contract testing and trying ...
# general
d
Hi there, I am new to contract testing and trying to understand how does it replace Integration tests. While going through this blog: https://pactflow.io/blog/contract-testing-vs-integration-testing/ I would like to understand more on "They focus on testing a single integration at a time without the need to deploy". Does it mean we need to write mock for provider behavior always if we are not deploying provider service? But then once I develop provider service, why will I use mock?
m
It doesn't necessarily replace integration testing, but might replace end to end integration testing. Think of Pact as a unit testing tool, then you'll see why we use mocks in consumer tests.
You shouldn't have external dependencies during unit tests because they make your tests nondeterministic
d
I think, I need to rephrase my question. Steps in contract tests: 1. Write tests at consumer end. 2. Execute these tests at consumer end and generate a contract file. 3. Upload a contract file on pact-broker. This is shared with provider. 4. On provider end: Replay the same API calls as given in contract file against the provider service. Here, I am executing a provider CI/CD pipeline. So, I do not have provider instance running. Then how can I replay the tests from contract file against provider and get the results for comparison? 1. Do we need actual provider instance already running? 2. Or do we need to create a mock service to depict the behaviour of a provider service? Let’s say add_role service is trying to establish a contract with create_user service. add_role is a consumer, which expects create_user to return {userid} in response. Now I have defined a contract test saying "As a add_role, I expect userid is present is response" I will run this test in consumer (add_role service) pipeline. And I will generate a contract file. Now as part of provider pipeline, before I build create_user service, I am going to execute contract tests. But then how can I get the response back from create_user service with userid if create_user is not running? I am confused here with provider part. Could you please help.
y
Here, I am executing a provider CI/CD pipeline. So, I do not have provider instance running.
You start up your service with the CI pipeline, such that it can receive the requests that are being replayed by the Pact verifier
d
I did not get you here when you say start service with CI, unless I deploy I cannot start the service is what I understand. If possible could you please provide links to video, article, code anything which gives idea about how provider CI pipeline and provider tests are written.
y
https://docs.pactflow.io/docs/workshops/ci-cd/ https://docs.pactflow.io/docs/examples#demos
I did not get you here when you say start service with CI, unless I deploy I cannot start the service is what I understand
It’s possible to stand up an application to run locally, or in a ci/cd system. The specifics of which are probably a discussion with your developers, I am assuming you are not directly developing the situation yourself. The specifics of which will differ depending on which language/framework you are using. All of our examples utilise this pattern. Some start the applications programmatically during a test, others start the application as a separate process
m
Put another way, usually you wouldn't test against a live system with Pact. This is because it's now testing many layers of your application and is susceptible to all of the problems of e2e testing, that we're aiming to avoid with contract testing
d
@Yousaf Nabi (pactflow.io) I will go through examples thanks for the links 👍
👍 1