Testing Architecture, Release Gates & Design Review
A mature test suite is a quality system, not a folder of specs.
It connects:
requirements
→ architecture
→ test boundaries
→ CI gates
→ deployment confidence
→ production feedback
1. Test ownership follows architecture ownership​
If a team owns a feature, it should own the confidence model for that feature.
For a vertical slice:
feature/
├── domain
├── data
├── server actions
├── route UI
└── tests
The team should be able to answer:
which rules are unit-tested?
which DB contracts are integration-tested?
which user journeys are E2E-tested?
which production risks are monitored?
2. Define a release confidence contract​
A useful release gate can require:
typecheck
lint
unit/component tests
integration tests
production build
critical E2E
security regression suite
selected accessibility checks
Performance/load/cross-browser depth can run at different cadences according to risk.
3. Required checks must be meaningful​
A green required check should imply a real quality claim.
Weak gate:
unit tests passed
for an app whose main risk is async RSC routing, auth, and browser navigation.
Stronger portfolio:
fast domain tests
+ DB/security integration
+ production build
+ critical E2E
4. Keep the build as a test boundary​
next build catches classes of failure that unit tests do not:
route compilation
module-boundary errors
static generation failures
configuration problems
server/client import mistakes
Do not skip the production build because component tests are green.
5. Critical-path E2E is a release gate​
A small reliable suite is better than a massive flaky gate.
Critical examples:
public entry
sign in
protected read
critical mutation
logout/revocation
one representative navigation/streaming path
Add journeys according to business risk.
6. Security quality gates​
High-risk applications should require regression tests for:
tenant isolation
role/permission enforcement
session lifecycle
critical CSRF/XSS/SSRF protections
webhook signatures
secret exposure
Security tests belong in normal engineering flow, not only annual audit work.
7. Performance quality gates​
Use stable signals:
bundle budget
query count
payload size
controlled synthetic thresholds
critical route p95 under repeatable load
Field metrics remain the final production truth, but CI should prevent obvious regressions.
8. Accessibility quality gates​
A mature model combines:
lint/static checks
semantic component tests
automated browser scans
keyboard E2E
manual assistive-tech review
Do not make one scanner represent the whole accessibility programme.
9. Test production failure modes​
Architecture review should ask whether tests cover:
dependency timeout
provider 429/500
DB conflict
cache miss/stale entry
revoked session
retry/double submission
browser refresh during mutation
network loss
third-party script failure
Resilience behaviour is product behaviour.
10. Observability closes the loop​
Phase 14 established logs, traces, metrics, and error events.
Testing should verify that critical failures produce enough evidence to debug:
request ID
trace ID
release/build ID
stable error code
redacted context
Avoid tests that merely assert console.error was called if production uses structured telemetry.
11. Production incidents should create tests​
When an incident reveals a gap:
understand root cause
→ choose cheapest boundary that reproduces it
→ add regression test
→ add observability if detection was weak
→ update runbook/gate if systemic
Do not always add a browser E2E test; choose the boundary that best captures the bug.
12. Test debt is architecture debt​
Signs of unhealthy test debt:
suite takes hours for small change
many retries
large quarantine list
selectors break on styling refactor
shared test accounts
cannot run locally
mocks know internal implementation
production bugs repeatedly escape same boundary
Track and prioritize it like performance/security debt.
13. Measure suite health​
Useful metrics:
PR feedback time
first-attempt pass rate
flake rate
quarantine count
critical E2E duration
mean time to diagnose CI failure
escaped regression category
Do not optimize only total test count.
14. Change-based test selection​
Large repositories may run targeted tests based on dependency graphs.
But critical global gates should remain broad enough to catch shared-framework regressions:
sidebar/router/config changes
shared auth
shared cache/data layer
root layout/providers
build configuration
Incorrect test selection can create false confidence.
15. Monorepo testing​
In a monorepo distinguish:
package unit tests
package integration/contract tests
application build
cross-package E2E
Shared packages should not need a full Next application to test pure logic.
App-specific framework integration still needs application-level tests.
16. Feature flags and experiments​
For a flag test:
default path
new path
unauthorized/unsupported combinations
migration/rollback state
Avoid combinatorial explosion by testing policy exhaustively lower in the stack and representative journeys in E2E.
17. Migration test strategy​
For framework upgrades:
baseline green suite
upgrade dependency
run production build
run critical E2E
compare bundle/performance
inspect warnings/deprecations
re-run security/cache/navigation regressions
Phase 20 will turn this into an upgrade playbook.
18. Testing configuration is production code​
Treat:
vitest/jest config
playwright/cypress config
CI workflows
fixture builders
mock servers
DB reset tooling
with code review, ownership, and versioning.
Broken test infrastructure can block releases or create false green signals.
19. Test-only production surfaces are dangerous​
If experimental/testing APIs must be exposed in a preview build:
guard by explicit test environment
never enable on public production
verify deployment configuration
A test helper should not weaken the live application's trust boundaries.
20. Senior design review template​
For a new feature ask:
Behaviour​
- What must work?
- What errors are expected?
- What state must survive navigation/retry?
Security​
- Who may read/mutate?
- What cross-tenant/resource cases must fail?
Data/cache​
- What persistence/cache layers participate?
- What freshness is required?
Browser​
- Does routing, streaming, hydration, focus, or layout matter?
External systems​
- Which provider contracts need sandbox/integration coverage?
CI​
- What is the cheapest reliable required gate?
- What evidence is captured on failure?
21. Example architecture: multi-tenant project creation​
parse form input
→ unit
authorization policy
→ unit matrix
DB tenant-scoped command
→ integration
Server Action security + expected errors
→ integration/direct boundary
form pending/validation UI
→ component
signed-in create-project journey
→ E2E
wrong-tenant direct mutation
→ security integration + representative E2E
revalidation shows new project
→ E2E
No single test owns the entire confidence story.
22. Definition of done for testability​
A feature is not done when tests are added mechanically.
It is done when:
critical behaviour has an owner
risk has an appropriate test boundary
negative cases exist
production build is represented
CI failure is diagnosable
known test debt is explicit
Phase 16 completion model​
Phase 16 defines the handbook testing baseline as:
risk-driven portfolio
+ Vitest/Jest/RTL lower layers
+ realistic server/data/cache integration
+ direct mutation/API/security tests
+ real-browser routing/streaming/hydration confidence
+ Playwright/Cypress production-build E2E
+ deterministic test infrastructure
+ CI/release gates
+ experimental Next testing helpers clearly isolated
Production checklist​
- quality gates correspond to real product risks
-
next buildis part of release confidence - async RSC behaviour has E2E coverage
- security and tenant isolation are required regressions
- suite health/flake metrics are visible
- incidents produce appropriately placed regression tests
- test infrastructure has owners
- test-only APIs cannot reach live production
- performance/accessibility checks exist at appropriate cadence
- test debt is tracked and reduced
Interview questions​
How would you design testing for a large Next.js app?​
Start from feature/business risk, keep pure policy and component tests fast, test real database/provider contracts where those systems affect correctness, use production-build E2E for App Router composition, and make security, build, critical journeys, and diagnosable CI required gates.
What makes an E2E suite unhealthy?​
Excessive setup through UI, shared mutable data, sleeps, implementation selectors, duplicated lower-level permutations, unreliable external dependencies, slow feedback, and failures that lack traces/logs.
How should production incidents change testing architecture?​
Add the smallest regression test that reproduces the root cause, strengthen the missing observability or contract, and update systemic release gates only when the incident exposed a recurring class of risk.