Skip to content

description: Master decision matrix — map any verification need to the right test type and the right guide, with quick-reference by stack. tldr: Map what you need to verify to the correct test type using this matrix. Most features need a combination: unit tests for logic, integration for seams, E2E for critical journeys only. Quick reference: Drupal uses PHPUnit Unit/Kernel/Functional; React/Next.js uses Vitest + RTL + Playwright.


Choosing a Test Type

When to Use

Use this master decision matrix when you know what you need to verify but are not sure which test type to reach for.

Decision

I need to verify... Primary test type Secondary / complement Cross-link
A function's return value for given inputs Unit Parameterized unit for edge cases Unit Testing Concepts
A class behaves correctly when dependencies return specific values Unit (with stubs) Test Doubles
A service correctly queries and transforms database data Integration (real test DB) Unit for transformation logic Integration Testing Concepts
An HTTP endpoint returns the correct response shape Integration (HTTP layer) Unit for business logic inside Integration Testing Concepts
A multi-step workflow end-to-end within one process Functional / system Integration for individual seams Functional Testing Concepts
A critical user journey through a real browser E2E Integration for logic; unit for components E2E Testing Concepts
A UI component renders correctly without regression Visual regression Unit/Integration for behavior Visual Regression Concepts
An API consumer and provider stay in sync Contract test Integration for each side independently Contract & API Testing Concepts
System behavior under concurrent users / load Load/performance test Unit for algorithmic bottlenecks Performance Testing Concepts
A page has no WCAG violations Automated a11y (axe) Manual keyboard + screen reader Accessibility Testing Concepts
A React/Next.js component's interactive behavior Integration (Testing Library) Unit for pure logic Integration Testing Concepts
Drupal form submission, validation, redirects Drupal Functional (BrowserTestBase) Kernel for service logic drupal/testing
Drupal plugin / hook / service behavior Drupal Kernel (KernelTestBase) Unit for pure logic drupal/testing
Drupal E2E with Playwright against a DDEV site Playwright + ATK VR for visual stability testing/playwright, testing/atk
AI-generated tests match spec and cover edge cases AI test generation workflow Unit + integration for gap coverage testing/ai-test-generation

Pattern

Feature: User Registration

Unit tests:
  - Email format validation logic
  - Password strength rules
  - Hash function produces correct output format

Integration tests:
  - Registration endpoint: saves user to DB, returns 201
  - Duplicate email: returns 409 with correct error body
  - Weak password: returns 400 with validation errors

Functional tests:
  - Full registration form submission through Drupal
  - Email confirmation flow

E2E test:
  - One test: user fills form, submits, sees confirmation page

Security tests (integration level):
  - SQL injection payload returns 400, not 500
  - Token in response is signed and contains correct claims

Quick reference by stack:

Stack Unit Integration E2E
PHP/Drupal PHPUnit Unit PHPUnit Kernel PHPUnit Functional / Playwright
JavaScript/React Vitest/Jest React Testing Library Playwright
TypeScript/Next.js Vitest/Jest Supertest + Testing Library Playwright
Python pytest pytest with real DB Playwright / Selenium
Go testing package httptest + real DB Playwright

See Also