The Difference between GUI, API and Unit Tests (an Illustrative Example)

No votes yet.
Please wait...

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 Pyramid of UI, API, and Unit Tests

The Pyramid of UI, API, and Unit Tests

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:

  1. Unit tests are checks of small functions (integration testing);
  2. API tests are tests of a particular functionality;
  3. 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.

In Conclusion

What do we have at the bottom line?

In software:

  1. Unit – checking small functionality separately;
  2. API – tests of specific functionality, consisting of many small functions;
  3. 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.

Leave A Comment