vendredi 9 juin 2017

How to determine the ratio between unit and end to end tests in web application?

We know by test pyramid that there should be more unit tests than end to end tests.

But question is how to get the right ratio?

Is it good if we have 49 % end to end tests, and 51 % unit tests?

I am having in mind web application api endpoints tested with codeception and phpunit.

Or should we aim for 10 % end to end tests and 90 % of unit tests.

By those percents I mean if we covered x % with end to end tests, then do not cover same code with unit tests.

But I mihgt be wrong, maybe we need to cover same lines with unit tests even if they are covered by end to end tests, as Martin Fowler writes here:

http://ift.tt/2iLywih

I always argue that high-level tests are there as a second line of test defense. If you get a failure in a high level test, not just do you have a bug in your functional code, you also have a missing or incorrect unit test. Thus I advise that before fixing a bug exposed by a high level test, you should replicate the bug with a unit test. Then the unit test ensures the bug stays dead.

We usually do not cover same code with unit tests now if it is covered by end to end tests to save development time.

But if we need to cover same code with unit tests, then it means we should cover with end to end as little as possible but at least one basic call to API endpoint, because it should be covered by unit tests anyway.

Aucun commentaire:

Enregistrer un commentaire