Phase 3: Testing Strategies, Test-Driven Development, and Ephemeral Environments
A resilient software delivery lifecycle relies on a balanced Testing Pyramid, automated test data factories, integration testing against real databases using Testcontainers, and ephemeral PR preview environments.
⚡ Quick Dive
The Practical Testing Pyramid
/ E2E Tests \ (Slow, High Maintenance - 5%) --> Playwright / Cypress
/ Integration \ (Fast, Real Containers - 25%) --> Testcontainers
/ Unit Tests \ (Ultra-Fast, In-Memory - 70%) --> Jest / pytest / go test
| Test Layer | Execution Speed | Scope | Mocking Strategy |
|---|---|---|---|
| Unit Tests | ⚡ Milliseconds | Single function / pure business logic | Mock all external I/O |
| Integration Tests | Seconds | Repository $\leftrightarrow$ Database, Queue handlers | Real ephemeral Docker containers |
| End-to-End (E2E) | Minutes | Complete user journeys through web UI / Gateway | Minimal mocking (Stripe sandbox) |
📖 Extended Guide
1. Test-Driven Development (TDD) Cycle
[ 1. RED ] ──► Write a failing unit test asserting expected behavior
│
▼
[ 2. GREEN ] ──► Write the minimal production code necessary to pass the test
│
▼
[ 3. REFACTOR ] ──► Clean up design, remove duplication, maintain passing tests
2. Ephemeral Preview Environments on Pull Requests
Using GitHub Actions and cloud deploy hooks, spin up an isolated, full-stack preview environment per Pull Request:
# .github/workflows/preview-deploy.yml
name: Deploy PR Preview Environment
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy Ephemeral Environment
run: |
echo "Deploying branch ${{ github.head_ref }} to preview namespace..."