Generalized testing

From jleechanorg/claude-commands · View interactive version

Generalized testing is an AI agent skill from the GitHub repository jleechanorg/claude-commands. Generate comprehensive, systematic test suites for any system component using a structured test design methodology. Creates tests that catch real bugs through state lifecycle, integration, and consistency testing.

How to use this skill

Skill file

Generalized Test Suite Generation

Overview

Generate comprehensive test suites for any system component by systematically analyzing failure modes, state transitions, and integration points. This methodology is derived from the successful modal state management test suite that caught routing consistency bugs.

The Process

1. Understanding the Component

Analyze the system you're testing:

Ask clarifying questions:

2. Test Architecture Planning

Use the recommendations below as defaults. Ask only about a material decision the available context and project rules cannot resolve; batch remaining questions instead of asking sequentially.

  1. Test Organization: Single file, modular by concern, or hybrid with base class?
  1. Test Data Strategy: Factory functions, builder pattern, or fixture dataclasses?
  1. Component Coverage: Which components/subsystems to prioritize?
  1. Assertion Strategy: Direct assertions, snapshot-based, or custom semantic helpers?
  1. Test Execution Level: Pure unit tests, integration via public APIs, or hybrid?
  1. Advanced Testing: Include property-based tests now or later?

3. Test Categories to Design

State Lifecycle Tests

Cross-Component Interaction Tests

Logic Consistency Tests

Property-Based Invariants (document for later)

4. Creating the Test Suite

File Structure Pattern:

tests/
├── test_<component>_base.py           # Base class + fixtures + assertions
├── test_<component>_lifecycle.py      # State transition tests
└── test_<component>_integration.py    # Cross-component + consistency tests

Base Class Components:

@dataclass
class TestScenario:
    name: str
    initial_state: dict
    action: Callable | str
    expected_state: dict
    description: str = ""

class TestBase(unittest.TestCase):
    # Custom assertion helpers (semantic)
    def assert_no_component_active(self, state): ...
    def assert_only_component_active(self, state, name): ...
    def assert_stale_flags_cleared(self, state, component): ...
    def assert_logic_consistency(self, state, action): ...

    # Scenario execution
    def run_scenario(self, scenario: TestScenario): ...

    # Test fixtures
    def create_base_state(self, **kwargs): ...

Test Pattern:

def test_<bug_or_behavior_description>(self):
    """
    BUG FIX TEST or BEHAVIOR TEST:
    Clear description of what this verifies and why it matters.
    """
    scenario = TestScenario(
        name="descriptive_name",
        initial_state=self.create_base_state(...),
        action="user_action" or callable,
        expected_state={...},
        description="Why this test matters"
    )
    self.run_scenario(scenario)

5. Validation

Tests must:

Run tests and verify:

pytest tests/test_<component>_*.py -v

Key Principles

1. Test Real Failure Modes

2. Use Semantic Assertions

3. Declarative Test Scenarios

4. Integration Over Unit

5. Design for Extensibility

Example: Modal State Management Tests

Context: Modal routing system with character creation, level-up, and campaign upgrade modals.

Bugs Found:

Test Suite Created:

Files:

After Creating Tests

Documentation:

Maintenance:

Common Patterns

State Transition Pattern:

def test_state_clears_stale_flags():
    """When condition X triggers, stale flags Y should be removed."""
    # initial_state with stale flags
    # action that triggers new condition
    # verify flags removed (not just set False)

Cross-Component Pattern:

def test_component_exit_cleans_all_flags():
    """Exiting component A clears flags from ALL components."""
    # initial_state with mixed flags
    # exit action
    # verify ALL component flags cleared

Consistency Pattern:

def test_decision_points_agree():
    """Decision point A and B must use identical logic."""
    # state that could be ambiguous
    # check both decision points
    # verify they agree on outcome

Meta-Advice

When to use this skill:

When NOT to use:

Success metrics:

Integration with Other Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.