Test-First Methodology
Strategy: Write comprehensive automated tests BEFORE refactoring to lock in current behaviour. Manual testing is a supplementary safety net, not the primary verification method.
Why Automated Tests First?
Safety net - Tests fail immediately if refactoring breaks something
Documentation - Tests document current behaviour precisely
Confidence - Can refactor aggressively knowing tests protect you
Regression prevention - Future changes won't break existing behaviour
Faster feedback - No need to manually click through every scenario
CI/CD integration - Tests run automatically on every commit
Test-First Workflow
For each phase:
Write automated tests FIRST for current behaviour (characterisation tests)
Verify tests pass with current implementation (establish baseline)
Make refactoring changes to implementation
Tests should still pass (green to green refactor)
Add new tests for improved functionality if needed
(Optional) Run manual test checklist for extra confidence
Test Coverage Requirements
Before Starting Any Phase
You MUST have automated tests covering:
All derived boolean values (
isCurrentCanvasRestricted,hasMultipleCanvases, etc.)All navigation state (
isFirstCanvas,canNavigateNext, etc.)All edge cases (undefined canvas, empty manifest, restricted access, etc.)
Component integration (components actually read from context correctly)
Minimum Test Files Required
For Phase 1 (Canvas Data), you need:
Context unit tests -
ItemViewerContext.V2.test.tsxTest all derived canvas data calculations
Test all boolean flags
Test edge cases (undefined, null, empty arrays)
Component integration tests -
IIIFViewer.refactored.test.tsx,ViewerTopBar.refactored.test.tsxVerify components consume context values
Verify conditional rendering based on boolean flags
Verify navigation state affects UI correctly
Mock utilities -
test-utils.tsProperly typed mock contexts
Reusable test fixtures
See refactoring-iiif-viewer-context-testing.md for complete test examples with TypeScript types.
Test-First Benefits
What You Get
Immediate feedback - Know instantly if something breaks
Refactoring confidence - Change code fearlessly
Living documentation - Tests show how code should behave
Onboarding tool - New developers learn from tests
CI/CD ready - Automated verification on every push
What You Avoid
Manual testing every change
"Did I break something?" anxiety
Regression bugs shipping to production
Time-consuming QA cycles
Relying on memory for edge cases
When to Use Manual Testing
Manual testing is supplementary, not primary. Use it to:
Verify visual appearance - Automated tests don't check if UI looks right
Test interactions - Complex user flows that are hard to automate
Cross-browser testing - Ensure consistency across browsers
Extra confidence - Double-check critical paths before release
See 13-testing-strategy.md for the complete manual testing checklist.
Red-Green-Refactor Cycle
For this refactoring, we're doing GREEN to GREEN refactoring:
Tests pass with current implementation (GREEN)
Refactor code
Tests still pass with new implementation (still GREEN)
Automated Test Examples
See detailed examples in refactoring-iiif-viewer-context-testing.md.
Last updated