pactflow / example-consumer-cypress

Demonstrate running a consumer pact test with Cypress
MIT License
33 stars 23 forks source link

Question? #2

Closed Romanchuk closed 3 years ago

Romanchuk commented 3 years ago

Hello, i found your repository by googling how to integrate cypress and pact. Thank you for cool example, i'll try it in my projects for sure.

But here is the question came to my mind after some research: At first, what i'm trying to achieve - implements single test that can runs on two levels depends of environment. There are two levels: 1) Unit test level, Front-end developer writes isolated test with stubbed request. It tests only UI. 2) CI level, run these UI test against real API and DB (with seeding DB and etc). IT tests whole application. Max trustworthy test.

Cypress by it self is quiet configurable and we can use environment variable to set local or CI run of our tests. Then in each test i need to add condition. ` if (env.CI) { cy.task('db:seed'); } else { cy.server() cy.routes } ....

` And it looks for me like i did with only Cypress the same that would Pact do for me. So it looks like using Pact is overhead, because one tool is enough. I might misunderstand the whole idea. Please tell me what do u think?

mefellows commented 3 years ago

Sorry @Romanchuk, I somehow missed this issue.

And it looks for me like i did with only Cypress the same that would Pact do for me. So it looks like using Pact is overhead, because one tool is enough. I might misunderstand the whole idea. Please tell me what do u think?

No, Cypress does not do contract testing. Using Pact, you can verify that the mocks you use in Cypress are actually true representations of the real provider.

In many cases, this removes the need to do step (2) where you have to do end-to-end integrated tests against a real provider (that gets complicated and painful as you move more quickly, have more people and have more systems).

You may want to see more about pact here: https://www.youtube.com/playlist?list=PLwy9Bnco-IpfZ72VQ7hce8GicVZs7nm0i and docs.pact.io.

See also https://pactflow.io/blog/cypress-pact-front-end-testing-with-confidence/