API Testing vs UI Testing: What Each One Finds, and How to Use Both

API testing vs UI testing: what each one finds and misses, and how one test sets up through the API, uses the app, and checks the screen and the server.

By Ait Nohaila, Business Development Representative 12 min read

API testing checks what a server answers, and UI testing checks what a person sees and can do on the screen. Each one misses what the other finds, so the strongest end-to-end test uses both.

Picture a release where every test is green. The API tests pass, the UI tests pass, and a customer still writes: the app said Paid, and her order was never sent. No test had followed her click all the way to what the server saved.

What is the difference between API testing and UI testing?

Definition

API testing talks to the server, and UI testing uses the app.

  • An API test sends a request, such as create this order, and checks the status and the values of the answer.
  • A UI test (user interface test) clicks, types and reads the screen, the way a user does.

One checks the work behind the screen, the other checks the screen itself.

  • The screen

    API testNever reaches it

    UI testChecks it

  • What the app does with a click

    API testNever reaches it

    UI testChecks it

  • The API and its rules

    API testChecks it

    UI testGoes through it

  • The saved data

    API testChecks it

    UI testGoes through it

A UI test uses the API without looking at its answers, and an API test never opens the app. Together, they check all four layers.
QuestionAPI testingUI testing
What does it use?Requests sent to the server.The real app: mouse, keyboard and screen.
What does it check?Statuses, values, headers and response times.What is shown, where it stands, and what it says.
How long does it take?As long as its requests take, so it is usually short.As long as the app takes to open and respond.
What makes it need a change?The API changes its addresses or its data.The workflow or the look of the app changes.
What does it prove?The rules are right and the data is saved.A person can do the task and sees the right thing.

Which bugs does each one find?

Take the bugs of one shop, and ask who would have caught each of them.

The bugAPI testUI test
The server calculates a wrong totalFinds itFinds it, if a check reads the total
The quantity is saved wrong, and looks right on the screenMisses it: it sends its own quantityMisses it, unless the app loads the order again
A customer can read another customer's orderFinds itMisses it: the screen never offers that order
A banner covers the Pay buttonMisses itFinds it
The total cannot be read in dark modeMisses itFinds it, when it runs in dark mode
The app still shows the old status after the paymentMisses itFinds it

The refusals and the limits are quickest to cover through the API: see API test cases with examples.The bugs only eyes can see are the subject of visual bugs your automated tests miss.

API testing vs integration testing and end-to-end testing

These names answer different questions, so one test can carry two of them. API and UI say where the test enters. Integration and end-to-end say how much it covers.

NameThe question it answersExample
API testingDoes the server answer as it should?Create an order, and check the 201 and the id.
UI testingCan a person do this, and see the right result?Click Pay, and check that the screen says Paid.
Integration testingDo these parts work together?An order request goes through the order service to the real database.
End-to-end testingDoes the whole workflow work, for its user?Choose an item, pay, and find the order in the list.

A request that reaches a real database is an API test and an integration test.A chain of requests that follows one order to its end is an end-to-end test of the API, and adding the interface makes it an end-to-end test of the product.Read more in end-to-end testing vs integration testing and what is end-to-end testing.

The screen says Saved, the server says nothing

A tester changes the quantity from 1 to 3 and clicks Save. The screen shows 3, and the word Saved appears. The recorded check passes at every run.

What the screen shows

Quantity3

Saved

The check of the screen passes.

What the server holds

GET /orders/1042 { "quantity": 1 }

The Call API step fails: quantity is 1, and 3 was expected.

The same order, a second after the click on Save. Only the question to the server finds the bug.

This can happen in several ways.

  • The app shows Saved before the server has answered.
  • It sends the old value in its request.
  • The server refuses the change, and the app ignores the refusal.

Each time, the screen shows what the app remembers, not what was saved.

The fix is one more step: after the click, a Call API asks for the order and checks that quantity equals 3.With Keep trying until it passes, it asks again every second, up to the time you allow, so a server that needs a moment does not fail the test.

To look at the request the app itself sent, use a Check Network step.See wait for an API response in UI tests and the network activity and logs guide.

The API is right, the button is hidden

Now the opposite. The payment API passes all its tests. A cookie banner added this week covers the Pay button on small screens, and nobody on a phone can pay.

An API test sends its request whatever the screen looks like.

  • It cannot see a covered button.
  • It cannot see a label cut in French.
  • It cannot see a total that is too pale to read.
  • It cannot see a page that never opens.

Only a test that uses the app as people do can find these.GUI Test Studio clicks the real button and compares what it shows perceptually, like a human eye.Cross-browser testing shows how one recorded web test also runs on other browsers and screen sizes.

Use both in one test: set up, act, check, clean up

You do not have to choose one. Each moment of a test has a way that suits it best.

  1. 1. Set upAPICreate the order the test needs.
  2. 2. ActInterfaceOpen it and pay, as a user does.
  3. 3. CheckInterfaceAPIPaid on the screen, and paid on the server.
  4. 4. Clean upAPIDelete the order.
The four moments of one test. The API does what needs no eyes, and the interface is used where a user would use it.

In GUI Test Studio, all four are steps of one visual timeline, with no code: that is end-to-end testing of the whole product.Your team decides what must be true on the screen and on the server.An AI agent can help build and change the test.The engine then runs it and checks both sides the same way at every run.

Use the interface for what you are testing, and the API for everything around it.

Test data setup: create test data through an API

Most workflows start from something that already exists: a client, an order, a signed-in account. Here are the usual ways to get it.

Where the data comes fromWhat you gainWhat to watch
Click through the app firstNothing to prepare.Every test repeats those clicks, and fails when they fail.
Use data left on a shared serverIt is there at once.Someone changes or deletes it, and your test fails without a bug.
Write into the databaseAny state you want.It goes around the product's rules, so it can make data the app never would.
Create it through the APIOne step, with the product's own rules, new at every run.When that request fails, the test stops there and says why.

Give the data a name that is new at every run, such as {{$randomText}} in a client's name, or {{$uuid}} where an id is needed.These values are new at every use, not only at every run.So write one once, in the request that creates the data, and save the name from the server's answer for the later steps.

ExampleA client that exists only in this run

A Call API creates a client named QA {{$randomText}}, then saves the answer's name as clientName.A Text Assert that expects {{clientName}} then finds that very client in the app's list.

Sending, checking and saving are explained one by one in API testing without code.For one test that runs against several servers, see environment variables in API testing.

A worked example: pay an order, and prove it on the server

The shop is a web app. The test must prove that a customer can pay an open order, and that the server knows it.

  1. 1

    Record what the user does

    In GUI Test Runner-Recorder, record the workflow on an order made for it: open its page, click Pay, and stop once the screen says Paid.

  2. 2

    Create the order at the start

    Open the test in GUI Test Studio and add a Call API step that sends POST {{baseUrl}}/orders.It expects 201 and saves the answer's id as orderId.

    Place it before the Open Web App.A recorded web test opens its page at the very start, so give the Open Web App a slightly later Position.

  3. 3

    Open that very order

    In the Open Web App's address, replace the recorded order's number with the variable: https://shop.example.com/orders/{{orderId}}.

  4. 4

    Check the screen

    Let a Text Assert expect Order {{orderId}}, and another one expect Paid.The order's number is new at every run, so keep it out of the pictures the test checks: visual checks shows how to choose what a picture holds.

  5. 5

    Ask the server

    Add a Call API step that sends GET {{baseUrl}}/orders/{{orderId}} and checks that status equals paid.Turn on Keep trying until it passes: the test goes on the moment the server agrees.

  6. 6

    Delete the order, then run the test

    Add a last Call API step that deletes the order and expects the status your API documents, such as 204.Then run the test and read its report.

A Call API step in the Properties panel: its moment, its request, and what a failure does.

When this test fails, the failed step says where to look. If the screen never says Paid, start with the app. If it says Paid and the status stays open, look at the server, or at the request between the two.

How to clean up test data, even after a failure

The last step of the example deletes the order. When an earlier step stops the test, that last step never runs, and the order stays. After a week of failures, the list is full of orders nobody paid.

What to doHowWhen it fits
Make the data uniquePut {{$uuid}} or {{$randomText}} in its name.Leftovers do no harm, and a test server is emptied from time to time.
Clean up at the startGive the data a fixed reference of the test's own.The first step deletes it, and expects 204, 404: gone, or never there.Your API can delete by that reference, and one run uses it at a time.
Clean up at the endA last Call API step, as in the example.Always welcome, and never the only protection.
Let some checks go onSet If It Fails to Continue the test on checks the next steps do not need.A label is wrong, but the rest of the test still makes sense.

How a step waits and what its failure does are in timeouts, search areas and failures, and more habits like these in good practices.

API testing or UI testing: which one should you use?

Ask what you want to prove. The answer names the test.

What you want to proveWhat to use
A rule with many cases: prices, limits, rightsAPI tests, one for each case.
A refusal: no token, another user's orderAPI tests. Most screens never offer these requests.
A person can complete a taskA UI test of that workflow.
The screen looks and reads rightA UI test with visual and text checks.
What the screen says was really savedBoth, in one test: act in the app, then ask the server.
A workflow that needs data to start fromBoth: create the data through the API, then use the app.

Run them together at every build.Run tests in CI/CD shows how, with the address and the secrets of each environment kept out of the test.

What to know before you start

Good to knowWhat it means
You need a way to create dataNot every API lets a test create or delete what it needs. Ask the team that builds it: a request kept for the test server is often enough.
The test needs its own rightsIts account must be allowed to create and delete. Keep its password or token as a variable, never in the test.
Some work takes a momentPayments, emails and exports may finish after the screen. Allow the time of your slowest acceptable day.
Two runs at onceWith fixed data, they change each other's order. Unique data avoids it.
A test checks what it was told to checkA wrong value that nobody asked about passes, on the screen and on the server.

Key takeaways

  • 1API testing and UI testing look at two sides of one product: the server's answers, and what a person sees and does.
  • 2Each one misses bugs the other finds: some bugs only show when one test looks at both sides.
  • 3Prepare through the API: test data takes one step and follows the product's own rules.
  • 4Act in the app, then check twice: once on the screen, once on the server.
  • 5Never rely on the last step to clean up: make the data unique, or clean up at the start.

Questions

What is the difference between API testing and UI testing?

API testing sends requests to the server and checks its answers, while UI testing uses the app as a person does and checks the screen. The first finds wrong rules and wrong data. The second finds what stops a person from using the app.

Can API testing replace UI testing?

No. An API test never sees the screen, so it passes while a button is hidden, a label is cut or the app sends the wrong value. Cover most rules through the API, and keep UI tests for the workflows your users depend on.

Is API testing the same as integration testing?

Not exactly. API testing says where you test, and integration testing says what you test: whether two parts work together. A request that goes through the API, a service and a real database is both at once.

Is API testing part of end-to-end testing?

It can be. An end-to-end test follows a whole workflow, and API requests can prepare its data, check what the server saved and clean up. A chain of API requests that follows one order from start to finish is an end-to-end test of the API.

Should I create test data through the API or through the app?

Through the API, unless creating that data is what you are testing. One request makes it in a moment, with the same rules as the app. Click through the creation in one test of its own, and use the API in all the others.

How do I check that the data was really saved?

Ask the server after the action on the screen. Send a request for that order, check its values, and let the request be tried again for a few seconds when the server finishes after the screen.

How do I clean up test data when a test fails?

Do not count on a last step: when a test stops at a failure, the steps after it do not run. Give the data a unique name so that leftovers never get in the way, or remove the last run's data at the start of the test.

Can one test check the API and the interface without code?

Yes. In GUI Test Studio, a Call API step stands on the same timeline as the recorded clicks and the checks of the screen. It works with a web app, a desktop app or an Android phone.

All articles