Examples
Test Generation

Test Generation Workflow

Automatically generate comprehensive tests for your code.

Overview

This workflow creates tests by:

  1. Analyzing code structure and behavior
  2. Identifying testable units
  3. Generating test cases
  4. Running and validating tests

Complete Manifest

{
  "$schema": "https://hydra.opiusai.com/schemas/workflow/v1.0.json",
  "manifest_version": "1.0",
  "name": "Test Generation Workflow",
  "intent": "Generate comprehensive unit and integration tests for existing code",
  "context": {
    "language": "typescript",
    "test_framework": "Jest"
  },
  "steps": [
    {
      "id": "analyze_code",
      "name": "Analyze code structure",
      "action": "analyze_code",
      "parameters": {
        "focus": "functions, classes, methods, dependencies, side effects"
      }
    },
    {
      "id": "identify_test_cases",
      "name": "Identify test cases",
      "action": "design_architecture",
      "depends_on": ["analyze_code"],
      "parameters": {
        "focus": "happy paths, edge cases, error conditions, boundary values"
      }
    },
    {
      "id": "generate_unit_tests",
      "name": "Generate unit tests",
      "action": "generate_tests",
      "agent": "test_writer",
      "depends_on": ["identify_test_cases"],
      "parameters": {
        "focus": "isolated unit tests, mocking dependencies",
        "test_framework": "Jest",
        "coverage_target": 80
      }
    },
    {
      "id": "generate_integration_tests",
      "name": "Generate integration tests",
      "action": "generate_tests",
      "agent": "integration_tester",
      "depends_on": ["identify_test_cases"],
      "parameters": {
        "focus": "component interactions, API calls, database operations"
      }
    },
    {
      "id": "run_tests",
      "name": "Run test suite",
      "action": "execute_command",
      "depends_on": ["generate_unit_tests", "generate_integration_tests"],
      "parameters": {
        "command": "npm test -- --coverage"
      }
    },
    {
      "id": "fix_failing_tests",
      "name": "Fix any failing tests",
      "action": "edit_files",
      "depends_on": ["run_tests"],
      "parameters": {
        "focus": "fix test assertions, correct mocking, handle async"
      }
    }
  ],
  "outputs": {
    "type": "code",
    "expected_files": ["tests/**/*.test.ts", "__tests__/**/*.test.ts"]
  },
  "adapters": {
    "claude": {
      "mode": "sub_agent",
      "config": {
        "spawn_agents_per_step": true,
        "max_parallel_agents": 2
      }
    },
    "cursor": {
      "mode": "direct",
      "config": {
        "use_composer": true
      }
    }
  }
}

Test Categories Generated

Unit Tests

  • Individual function behavior
  • Class method testing
  • Edge cases and boundaries
  • Error handling
  • Mock external dependencies

Integration Tests

  • Component interactions
  • API endpoint testing
  • Database operations
  • External service mocking

Usage

With Claude Code

Run Test Generation workflow on src/services/UserService.ts
Target: 90% coverage

With Cursor

@hydra Generate tests for @src/utils/validation.ts
Include edge cases and error scenarios

Framework-Specific Examples

Jest (JavaScript/TypeScript)

{
  "context": {
    "test_framework": "Jest"
  },
  "steps": [
    {
      "id": "run_tests",
      "action": "execute_command",
      "parameters": {
        "command": "npx jest --coverage --passWithNoTests"
      }
    }
  ]
}

Pytest (Python)

{
  "context": {
    "language": "python",
    "test_framework": "pytest"
  },
  "steps": [
    {
      "id": "run_tests",
      "action": "execute_command",
      "parameters": {
        "command": "pytest -v --cov=src --cov-report=term-missing"
      }
    }
  ]
}

Vitest (Vue/Vite)

{
  "context": {
    "test_framework": "Vitest"
  },
  "steps": [
    {
      "id": "run_tests",
      "action": "execute_command",
      "parameters": {
        "command": "npx vitest run --coverage"
      }
    }
  ]
}

Generated Test Example

Input code:

// src/utils/math.ts
export function divide(a: number, b: number): number {
  if (b === 0) throw new Error('Division by zero');
  return a / b;
}

Generated test:

// tests/utils/math.test.ts
import { divide } from '../src/utils/math';
 
describe('divide', () => {
  it('should divide two positive numbers', () => {
    expect(divide(10, 2)).toBe(5);
  });
 
  it('should handle negative numbers', () => {
    expect(divide(-10, 2)).toBe(-5);
  });
 
  it('should handle decimal results', () => {
    expect(divide(7, 2)).toBe(3.5);
  });
 
  it('should throw error on division by zero', () => {
    expect(() => divide(10, 0)).toThrow('Division by zero');
  });
 
  it('should return 0 when dividing 0', () => {
    expect(divide(0, 5)).toBe(0);
  });
});

Customization

Higher Coverage Target

{
  "parameters": {
    "coverage_target": 95
  }
}

Focus on Specific Test Types

{
  "steps": [
    {
      "id": "generate_e2e_tests",
      "name": "Generate E2E tests",
      "action": "generate_tests",
      "parameters": {
        "focus": "end-to-end user flows, Playwright/Cypress"
      }
    }
  ]
}

Include Snapshot Tests

{
  "id": "generate_snapshots",
  "name": "Generate snapshot tests",
  "action": "generate_tests",
  "parameters": {
    "focus": "React component snapshots, UI consistency"
  }
}

Tips

  1. Start with critical code - Focus on business logic first
  2. Include edge cases - Null values, empty arrays, boundaries
  3. Mock external services - Keep tests fast and reliable
  4. Run often - Verify tests pass as they're generated