👍🏼 Tests the real behaviour
👍🏼 Catch performance issues
👍🏼 More confidence that critical paths are verified
👍🏼 Straightforward to test
👍🏼 Speeds up development
👍🏼 Speeds up testing
👍🏼 Quicker to run
👍🏼 Simulate delays
👍🏼 Avoids flaky tests as results are deterministic
👍🏼 Simulate different scenarios easily and test different status codes
👎🏼 Slower to run
👎🏼 Requires a dedicated environment
👎🏼 Can cause flaky tests if the API is still in development mode
👎🏼 Makes application under test dependent on other services
👎🏼 More effort to maintain
👎🏼 Bugs can be missed if mock API is not updated
Consider a Hybrid Approach
/// <reference types="cypress" />
describe('Todo API', () => {
it('returns a JSON data', () => {
cy.request('/todos')
.its('headers')
.its('content-type')
.should('include', 'application/json');
});
});