cypress-example-api-testing icon indicating copy to clipboard operation
cypress-example-api-testing copied to clipboard

Opinion: pattern for API testing

Open akauppi opened this issue 5 years ago • 0 comments

I looked at this repo as an authorative sample of using Cypress for REST API tests.

As such, I think it should present good ways of working. However, if I got it right, it currently uses one antipattern, here:

https://github.com/cypress-io/cypress-example-api-testing/blob/master/cypress/integration/example_spec.js#L37-L40

The mindset of Cypress testing should be to prepare and cleanup the backend directly, not via the API-under-test. This one seems to use the API itself.

Unfortunately, I don't know how to fix the sample. What I'm concerned about is that people will learn from this, and later - maybe - realize the pattern was not ideal. I ended up using direct node.js database client to do the setup/cleanup, whereas using my REST API only for things that get tested.

akauppi avatar Jan 17 '20 11:01 akauppi