Careeroza
What Should Not Be a UI Test
Move Checks Down
| Check | Best level | Why |
|---|---|---|
| Coupon SAVE10 gives 10% off with a ₹500 cap | unit / API | pure calculation; many combinations |
| Registration rejects 15 invalid emails | API (one UI test for the error message) | validation lives in the backend |
| Product search returns correct results | API | data and ranking, not layout |
| User can log in, search, add to cart and pay | UI | the real user journey across pages |
| Error message is shown in red under the field | UI (or visual testing) | only the browser renders it |
| Sort by price works on 40 products | API for the order, one UI test for the control | avoid reading 40 cards each time |
Checking API and UI Agree
Example
A common hybrid check: read prices from the API (fast, exact) and from the UI (formatted text), then compare. Here both lists are fixed values:
import java.util.*;
public class Main {
static double parseRupees(String text) {
return Double.parseDouble(text.replace("₹", "").replace(",", "").trim());
}
public static void main(String[] args) {
Map<String, Double> apiPrices = new LinkedHashMap<>();
apiPrices.put("Boat Rockerz 450", 1499.0);
apiPrices.put("Sony WH-CH520", 4490.0);
apiPrices.put("JBL Tune 510BT", 3299.0);
Map<String, String> uiPrices = Map.of(
"Boat Rockerz 450", "₹1,499",
"Sony WH-CH520", "₹4,490",
"JBL Tune 510BT", "₹3,499");
int mismatches = 0;
for (var e : apiPrices.entrySet()) {
double ui = parseRupees(uiPrices.get(e.getKey()));
boolean ok = ui == e.getValue();
if (!ok) mismatches++;
System.out.printf("%-17s api=%7.2f ui=%7.2f %s%n", e.getKey(), e.getValue(), ui, ok ? "OK" : "MISMATCH");
}
System.out.println(mismatches == 0 ? "PASS" : "FAIL: " + mismatches + " price(s) differ");
}
}Output
Boat Rockerz 450 api=1499.00 ui=1499.00 OK Sony WH-CH520 api=4490.00 ui=4490.00 OK JBL Tune 510BT api=3299.00 ui=3499.00 MISMATCH FAIL: 1 price(s) differ