Front-End Testing and Usability Validation
You need both kinds of validation: engineering tests prove the UI behaves as designed in every state; usability validation proves users actually understand it and can use it smoothly. The first is automated; the second comes from watching real users and reading real data.
Core concepts
| Type | What it checks | Tools |
|---|---|---|
| Unit tests | Pure functions, reducers, formatting logic | Vitest |
| Component tests | Rendering and interaction under different props/states | Vitest + Testing Library (React / Vue flavors) |
| E2E tests | Full flows in a real browser | Playwright |
| Automated accessibility checks | Automatically detectable a11y issues | axe (@axe-core/playwright, Storybook a11y addon) |
| Visual regression | Unintended style changes | Playwright screenshot comparison, Storybook-based services |
| Performance metrics | Loading and interaction responsiveness | Lighthouse, the web-vitals library, Chrome DevTools |
| Usability testing | Whether real users can complete tasks | Task-based tests, observation, interviews |
| Product data | Real usage after launch | Analytics events, funnels, retention |
How it works
1. Test the UI the way users use it
Testing Library's guiding principle: the more your tests resemble the way your software is used, the more confidence they can give you. So query by role and accessible name first (getByRole('button', { name: 'Retry from this step' })) rather than by class or test id. This checks accessibility as a side effect: if a button has no name, the test can't find it.
2. Cover every state with "scenario scripts"
Timing is the hardest part of testing live UIs. Record or write back-end event streams as scripts (JSON arrays) and replay them in tests:
| Script | States covered |
|---|---|
| happy-path | queued → running → succeeded |
| retry-then-success | retrying 2/3 → succeeded |
| partial-failure | partially_succeeded with 3 failed items |
| needs-human | waiting_human → user submits → running |
| disconnect | connection drops → reconnecting → recovered after replay |
Unit-test the reducer event by event; component and E2E tests use the same scripts, so "every state in the design has a test".
3. Why 5 users are worth testing
Jakob Nielsen's classic finding: qualitative testing with 5 users finds most usability problems, and it's better to run several small rounds, fixing issues between them. NN/g also stresses that this applies to qualitative testing; statistically reliable quantitative metrics need larger samples (their article suggests around 40 participants or more).
4. Rating severity
Following NN/g's approach to severity ratings, combine frequency, impact and persistence:
| Level | Meaning | Action |
|---|---|---|
| 4 Catastrophe | Users can't complete the task | Must fix before release |
| 3 Major | Seriously slows users down or causes errors | High priority |
| 2 Minor | Annoying but completable | Schedule a fix |
| 1 Cosmetic | Doesn't affect completion | Fix when there's time |
In practice
Reducer unit tests (Vitest)
import { describe, it, expect } from 'vitest'
import { reduce, initial } from './taskReducer'
import needsHuman from './scenarios/needs-human.json'
describe('taskReducer', () => {
it('enters the waiting-for-human state', () => {
const state = needsHuman.slice(0, 4).reduce(reduce, initial)
expect(state.status).toBe('waiting_human')
})
it('does not double-count duplicate events', () => {
const e = needsHuman[1]
const once = reduce(initial, e)
expect(reduce(once, e)).toEqual(once)
})
})E2E + accessibility check (Playwright)
import { test, expect } from '@playwright/test'
import AxeBuilder from '@axe-core/playwright'
test('a human request can be handled and the task continues', async ({ page }) => {
await page.goto('/tasks/demo?scenario=needs-human')
await expect(page.getByRole('status')).toContainText('Needs you')
await page.getByRole('button', { name: 'Handle it' }).click()
await page.getByRole('textbox', { name: 'Search keywords' }).fill('agent evaluation')
await page.getByRole('button', { name: 'Submit and continue' }).click()
await expect(page.getByText('Task continuing')).toBeVisible()
const results = await new AxeBuilder({ page }).analyze()
expect(results.violations).toEqual([])
})Running a usability test
| Step | What to do |
|---|---|
| 1. Goal | E.g. can users find out why a task failed and get it going again? |
| 2. Tasks | Describe a scenario without using UI wording: "Your research task seems to have stopped. Find out what happened and get it to finish." |
| 3. Participants | 5 people close to the target users; remote is fine |
| 4. Observe | Ask them to think aloud; observe without guiding; record success/failure, time and where they got stuck |
| 5. Summarize | Issue list + severity + how many people hit it + screenshots/clips |
| 6. Iterate | Fix the most severe issues, then rerun the same tasks next round and compare |
Optional: after the test, use the SUS (System Usability Scale, a 10-question survey) for a comparable satisfaction score.
Validating with data after launch
| Question | Event / metric |
|---|---|
| Do users handle human requests in time? | Distribution of time from request to response |
| Are error cards useful? | Share of "retry / edit / give up" clicks after failures; abandonment after failure |
| Is the timeline used? | Detail expansion rate, "jump to failure" clicks |
| Does the UI feel fast? | INP (Interaction to Next Paint, "good" at ≤ 200ms), reported with the web-vitals library |
Name events consistently (object_action, e.g. human_request_submitted) and attach context such as task status; collect only what's needed and never the text users type.
Common pitfalls
- Tests written against classes or DOM structure: break on every style change and miss accessibility problems.
- Only the happy path is tested: errors, partial success and disconnects, the states that most need tests, go untested.
- E2E depends on a real LLM: slow, costly and nondeterministic. Replay scripts or mock (e.g. MSW).
- Guiding users during usability tests: "You can click the button at the top right" makes the result meaningless.
- Percentages from a 5-person test: qualitative tests find problems; they can't support "80% of users are satisfied".
- Lots of events nobody looks at: every event should answer a specific question.
Common interview questions
- How would you design tests for a live-updating status UI?
- Why does Testing Library recommend querying by role?
- How do E2E tests avoid depending on a real back end and LLM?
- Why are 5 users enough for a usability test? When aren't they?
- How do you judge the severity of a usability problem?
- After launch, which data shows that "users understand task status"?
- What is INP, and what is the "good" threshold?
Related projects
- Agent Run Console: the 5 scenario scripts drive the demo, Vitest and Playwright alike; D18–21 runs a 5-person usability test and one iteration, written up on the case study page.
- This site: run Lighthouse and axe once to set a baseline for accessibility and performance.
Sources
- Testing Library: Guiding Principles / Query priority
- Vitest docs
- Playwright: Accessibility testing
- MSW (Mock Service Worker) docs
- NN/g: Why You Only Need to Test with 5 Users
- NN/g: How Many Test Users in a Usability Study? — sample sizes for quantitative studies
- NN/g: Severity Ratings for Usability Problems
- web.dev: Interaction to Next Paint (INP) / INP becomes a Core Web Vital
- GitHub: GoogleChrome/web-vitals
