behavior-driven-testing

Systematic testing methodology for exhaustive branch coverage, edge case identification, and production bug prevention. Use when PR review reveals incomplete test coverage, when tests pass but users report bugs, when code changes break existing features, when verifying all branches and edge cases before merge, when analyzing "it works on my machine" issues, when planning test strategy for new features, or when debugging flaky tests and race conditions.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "behavior-driven-testing" with this command: npx skills add robotlearning123/behavior-driven-testing/robotlearning123-behavior-driven-testing-behavior-driven-testing

Behavior-Driven Testing

Start from user behavior, not code structure. Every user-reachable path must be tested—no branch left uncovered, no edge case assumed.

Core Principles

  1. Behavior over Implementation - Test what users see, not how code works
  2. Exhaustive Coverage - Every branch, every condition, every edge case
  3. Context Awareness - Every test must define its preconditions explicitly
  4. Real Environment Validation - Mocks are tools, not destinations

Workflow Overview

Testing follows three phases. Follow them in order:

Analysis → Design → Execution → Verify Coverage → Ship (or loop back)

Analysis Phase:

  1. Requirements Definition - Define "correct" behavior with Gherkin specs
  2. Code Change Tracking - Know exactly what changed
  3. State Machine Analysis - Map all UI states and transitions
  4. Branch Mapping - Create the branch matrix (core artifact)

Design Phase: 5. Test Case Design - Apply equivalence partitioning, boundary analysis 6. Impact Analysis - Ensure new code doesn't break existing behavior 7. Test Prioritization - P0 (every commit) → P3 (periodic)

Execution Phase: 8. Test Data Preparation - Create fixtures, mocks, factories 9. Test Implementation - Write unit, integration, E2E tests 10. Test Execution - Run tests in phases (local → CI → staging) 11. Coverage Verification - Verify branch matrix completion

Quick Reference: Must-Test Branches

CategoryTest CasesPriority
Empty valuesnull, undefined, "", " " (whitespace), [], {}P0
Boundariesmin-1, min, min+1, max-1, max, max+1P1
Auth stateslogged in, logged out, loading, session expiredP0
API responses200+data, 200+empty, 400, 401, 403, 404, 500, timeout, offlineP0
User chaosdouble-click, rapid navigation, refresh mid-action, back buttonP1

The Whitespace Trap (Most Common Bug)

// ❌ WRONG - whitespace "   " is truthy!
if (!text) throw new Error('Required');

// ✅ CORRECT
if (!text?.trim()) throw new Error('Required');

Common Mistakes

MistakeWhy It's BadFix
Only happy pathError paths are 50% of codeTest ALL branches
Skip empty value testsMost common production bugsTest null, undefined, "", whitespace separately
Mock everythingMocks hide real problemsAdd integration + E2E tests
"Tested manually"Not repeatable, not reliableAutomate it
Ignore loading statesUsers interact during loadTest loading behavior
Skip double-click testUsers double-click everythingTest rapid interactions

Branch Matrix Template

For each code change, create a branch matrix:

| ID | Condition | True Behavior | False Behavior | Priority | Status |
|----|-----------|---------------|----------------|:--------:|:------:|
| B01 | user.isPremium | Skip credit check | Check credits | P0 | ⬜ |
| B02 | credits >= required | Proceed | Show error | P0 | ⬜ |
| B03 | credits == required | Boundary: Proceed | - | P1 | ⬜ |

Status: ⬜ Pending | ✅ Passed | ❌ Failed

Detailed References

Load these files only when you need detailed guidance:

Pre-Release Checklist

Before shipping, verify:

## Mock Tests (CI)
- [ ] All unit tests pass
- [ ] All integration tests pass
- [ ] Coverage thresholds met

## Real Tests (Before release)
- [ ] E2E tests pass on staging
- [ ] Manual smoke test on staging
- [ ] Core paths verified in real environment

## Branch Matrix
- [ ] All P0 branches tested
- [ ] All P1 branches tested
- [ ] No untested edge cases

## Production (After deploy)
- [ ] Smoke test passes
- [ ] Error rate monitoring normal

Related Skills

  • test-driven-development - Write tests first, then implementation
  • systematic-debugging - Debug issues methodically

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.