← Back to libraryQuestion 299 of 468
🏗️Framework DesignIntermediate

The Test Pyramid and API + UI Balance

📌 Definition:

The Test Pyramid guides how to distribute tests: many fast, cheap UNIT tests at the base, fewer INTEGRATION/API tests in the middle, and few slow, brittle UI/E2E tests at the top. Framework design should honor this balance.

📖 Detailed Explanation:

UI tests are valuable but slow and flaky, so you want FEW of them covering critical journeys, while pushing most coverage down to faster API and unit tests. An 'ice-cream cone' (mostly UI tests) is an anti-pattern — slow, brittle suites. A good framework makes it easy to test at the right level: API tests (REST Assured) for business logic and setup, UI tests only for what genuinely needs the browser, and uses API calls for UI-test SETUP (seed data fast, then verify one thing in the UI). Balancing the pyramid is a core design/strategy question.

🔑 Key Points:
  • Pyramid: many unit, fewer API/integration, few UI/E2E
  • UI tests are slow/brittle — reserve for critical journeys
  • 'Ice-cream cone' (mostly UI) is an anti-pattern
  • Use API for UI-test setup; push coverage down the pyramid
🌍 Real-World Example:

Instead of 500 UI tests, the team keeps ~50 UI tests for critical flows and moves the rest to fast REST Assured API tests, and uses API seeding to set up each UI test — cutting runtime from hours to minutes.

🎯 Scenario-Based Interview Question:

A suite of 400 UI tests takes 4 hours and is flaky. How does the test pyramid guide a redesign?