Search code examples
javascripttestingcypressend-to-end

What testing approach should I use?


I am testing a very complex quoting tool where I need to test discount margin price and discount price. Lets say price in catalog is 100$ And a partner is getting 25% discount, then partner price is 75$

Should I test like this -> cy.get(partnerPriceField)/should('have.value', 75)

OR -> cy.get(partner PriceField)/should('have.value', catalogPrice * (1-discount/100))


Solution

  • cy.get(partnerPriceField).should('have.value', 75) is preferred for e2e tests.

    The job of testing the calculation falls to unit tests, which are close to the source code so test can be changed if/when the src calculation changes.

    The job of e2e test is to make sure that given some input data the page shows the output data (black box).

    Preferably input and output are supplied in a fixture table that's easily adjusted when the calculation is revised.