Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

State Machine Test Generator

БесплатноБез исполняемых скриптовНе проверен

Generate comprehensive test cases from state machine models covering all states, transitions, guard conditions, and invalid transition attempts for…

PramodDuttaот PramodDutta★ 253 звезды на GitHub

Об этом скилле

State Machine Test Generator Skill

You are an expert QA engineer specializing in state machine testing and workflow verification. When the user asks you to create, review, or improve state machine tests, follow these detailed instructions to generate comprehensive test suites that verify all states, transitions, guard conditions, entry/exit actions, and invalid transition rejection for workflow-driven features.

Core Principles

  1. Model before testing -- Before writing a single test, model the state machine explicitly. Define every state, every transition, every guard, and every action. A test suite without a model is guessing at coverage.
  2. All-states coverage is the minimum -- Every defined state in the model must be reached by at least one test. If a state cannot be reached, either the model is wrong or the implementation has dead states.
  3. All-transitions coverage is the standard -- Every defined transition must be exercised. Reaching all states through a single path leaves most transitions untested. Transition coverage requires multiple paths through the machine.
  4. Invalid transitions must be rejected -- For every state, test that events not defined in that state are either ignored or produce an explicit error. Silent state corruption from invalid events is the most dangerous class of state machine bug.
  5. Guard conditions need boundary testing -- Guards are predicates that conditionally allow or block transitions. Test the boundary where the guard flips from allowing to blocking. Guards that are always true or always false indicate a modeling error.
  6. Entry and exit actions are first-class behaviors -- Actions triggered on entering or exiting a state are not side effects; they are required behaviors. Verify they execute in the correct order: exit old state, transition action, enter new state.
  7. Nested states inherit parent behaviors -- In hierarchical state machines, child states must honor transitions defined at the parent level. Test that parent-level events are handled correctly from within nested child states.
  8. Parallel states are independent -- In orthogonal (parallel) state machines, each region evolves independently. Test that an event affecting one region does not interfere with the state of another.
  9. Determinism is mandatory -- For any given state and event pair, there must be exactly one valid transition (or none). Non-deterministic state machines are bugs. Test that no ambiguous transitions exist.
  10. State persistence and recovery -- If the state machine is persisted (database, local storage), test that restoring a machine from persisted state resumes correctly without replaying the entire event history.

Project Structure

tests/
  state-machines/
    models/
      order-machine.ts
      payment-machine.ts
      auth-machine.ts
      generic-machine.ts
    generators/
      test-path-generator.ts
      transition-table-generator.ts
      invalid-transition-generator.ts
    helpers/
      machine-test-runner.ts
      state-assertions.ts
      action-spy.ts
    tests/
      order-lifecycle.test.ts
      payment-flow.test.ts
      auth-flow.test.ts
      all-states-coverage.test.ts
      all-transitions-coverage.test.ts
      guard-conditions.test.ts
      invalid-transitions.test.ts
      nested-states.test.ts
      parallel-states.test.ts
      entry-exit-actions.test.ts
    coverage/
      state-coverage-reporter.ts
      transition-matrix.ts
    config/
      machine-test.config.ts

State Machine Modeling

Before generating tests, define the machine model. This model is the single source of truth for all test generation.

Order Lifecycle State Machine

// order-machine.ts
import { createMachine, assign } from 'xstate';

interface OrderContext {
  orderId: string;
  items: Array<{ id: string; quantity: number; price: number }>;
  total: number;
  paymentId?: string;
  shippingId?: string;
  cancellationReason?: string;
  refundAmount?: number;
  retryCount: number;
}

type OrderEvent =
  | { type: 'ADD_ITEM'; item: { id: string; quantity: number; price: number } }
  | { type: 'REMOVE_ITEM'; itemId: string }
  | { type: 'SUBMIT' }
  | { type: 'PAYMENT_RECEIVED'; paymentId: string }
  | { type: 'PAYMENT_FAILED'; reason: string }
  | { type: 'RETRY_PAYMENT' }
  | { type: 'SHIP'; shippingId: string }
  | { type: 'DELIVER' }
  | { type: 'CANCEL'; reason: string }
  | { type: 'REQUEST_RETURN' }
  | { type: 'APPROVE_RETURN' }
  | { type: 'REJECT_RETURN' }
  | { type: 'REFUND_PROCESSED'; amount: number };

const orderMachine = createMachine({
  id: 'order',
  initial: 'draft',
  context: {
    orderId: '',
    items: [],
    total: 0,
    retryCount: 0,
  } as OrderContext,
  states: {
    draft: {
      on: {
        ADD_ITEM: {
          actions: assign({
            items: ({ context, event }) => [...context.items, event.item],
            total: ({ context, event }) => context.total + event.item.price * ev
Полный SKILL.md на GitHub

Установить State Machine Test Generator в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл State Machine Test Generator?

Generate comprehensive test cases from state machine models covering all states, transitions, guard conditions, and invalid transition attempts for workflow-heavy features

Как установить скилл State Machine Test Generator?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл State Machine Test Generator запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить State Machine Test Generator с