Every QA engineer knows about the standard pyramid of testing where unit tests are a basis of the whole software testing process, API is an interim stage, and finally, GUI tests which end the implementation of specified requirements to the final software version.
If we consider the pyramid in a programmatic context, we’ll get the following:
- UI tests – the most honest checks that show how a user would act with the software under test;
- API tests that eliminate all the superfluous;
- Unit tests – checks on the separate functional parts.
The tests should be created from the bottom part of such a pyramid since it will be better to test a little functional code at the beginning and only then to complicate the future tests:
- Unit tests are checks of small functions (integration testing);
- API tests are tests of a particular functionality;
- GUI tests are checks through a graphical interface (using the method of how would a user do that).
An Example of the Sequence of Unit, API, and GUI Tests
To make it more clear what we are talking about, let’s consider a simple example from life. Relatively speaking, you decided to order a new suit. The master took all the necessary measurements, listened to all your wishes, and got to work.
To begin with, he/she should cut a pattern and cut out the material (fabric for sewing). The job of checking every detail against the existing pattern is unit testing!
Have you tested every part individually? Now you need to check everything together. We check whether everything is smooth, nice, and user-friendly. This is a vivid analogy for performing API checks!
The costume is not ready yet, it is an unfinished thing. But we have already been able to connect some parts and analyze how they interact.
If everything is fine, the costume can be sewn! And then we can proceed with UI tests – the last group of checks when the thing is ready.
What do we have at the bottom line?
- Unit – checking small functionality separately;
- API – tests of specific functionality, consisting of many small functions;
- GUI – tests through a graphical interface (for example, to open a web browser, log in to an account, go to a product/service page, make a purchase/checkout of a necessary product or service).
Using the example of creating a costume:
- Unit – made a cut and checked all the details according to the pattern;
- API – we checked that everything fits smoothly, nicely, and conveniently;
- GUI – when the suit is ready, we perform a second check.