williamzujkowski

Unit Testing Framework Generator

3
0
# Install this skill:
npx skills add williamzujkowski/cognitive-toolworks --skill "Unit Testing Framework Generator"

Install specific skill from multi-skill repository

# Description

Coverage configuration and thresholds

# SKILL.md


name: Unit Testing Framework Generator
slug: testing-unit-generator
description: Generate unit test scaffolding and test suites for Jest, PyTest, Go testing, JUnit, RSpec with mocking, assertions, and coverage configuration
capabilities:
- Generate test file scaffolding for multiple frameworks
- Create mock objects and stubs for dependencies
- Configure coverage thresholds and reporting
- Generate property-based testing patterns
- Set up test fixtures and setup/teardown logic
inputs:
framework:
type: enum
values: [Jest, PyTest, Go, JUnit, RSpec]
required: true
target_code:
type: string
description: File path or code description to test
required: true
test_type:
type: enum
values: [unit, integration, e2e]
default: unit
coverage_threshold:
type: number
description: Minimum coverage percentage
default: 80
outputs:
test_files:
type: array
description: Generated test file contents with paths
config:
type: object
description: Framework configuration files
coverage_setup:
type: object
description: Coverage configuration and thresholds
keywords:
- testing
- unit-tests
- jest
- pytest
- junit
- rspec
- mocking
- coverage
- tdd
version: 1.0.0
owner: cognitive-toolworks
license: MIT
security: PUBLIC
links:
- https://jestjs.io/docs/getting-started
- https://docs.pytest.org/en/stable/
- https://pkg.go.dev/testing
- https://junit.org/junit5/docs/current/user-guide/
- https://rspec.info/documentation/


Unit Testing Framework Generator

Purpose & When-To-Use

Trigger conditions:
- Need to create unit tests for existing code
- Setting up test infrastructure for a new project
- Generating mocks/stubs for external dependencies
- Establishing coverage baselines and CI gates
- Converting manual test cases to automated suites

Use when: You have code that needs test coverage with framework-specific patterns, mocking strategies, and coverage enforcement.


Pre-Checks

Required validations before proceeding:

  1. Time normalization: Compute NOW_ET using NIST/time.gov semantics (America/New_York, ISO-8601)
  2. Input validation:
  3. framework is one of: Jest, PyTest, Go, JUnit, RSpec
  4. target_code is either a valid file path or parseable description
  5. coverage_threshold is 0-100
  6. Framework availability: Verify target runtime/language compatibility
  7. Source freshness: Documentation links valid as of NOW_ET = 2025-10-26T02:31:24Z

Procedure

T1: Basic Test Scaffolding (≀2k tokens)

Fast path for 80% of cases:

  1. Parse target code to identify:
  2. Functions/methods to test
  3. Input parameters and types
  4. Expected return values
  5. Generate test file with:
  6. Framework-specific imports
  7. Describe/test blocks or equivalent
  8. Basic assertions for happy path
  9. One edge case (null/empty/zero)
  10. Output minimal config (if missing):
  11. Jest: jest.config.js with basic settings
  12. PyTest: pytest.ini with test discovery
  13. Go: standard _test.go naming
  14. JUnit: pom.xml or build.gradle snippet
  15. RSpec: .rspec and spec_helper.rb

Token budget: ≀2k tokens for code analysis + generation


T2: Mocks + Coverage (≀6k tokens)

Extended validation with dependency mocking:

  1. Dependency analysis:
  2. Identify external calls (APIs, databases, file I/O)
  3. Map to framework-specific mocking patterns
  4. Generate mocks:
  5. Jest: jest.mock() or @jest/globals
  6. PyTest: pytest-mock fixtures or unittest.mock
  7. Go: Interface-based test doubles
  8. JUnit: Mockito or JUnit 5 mocking
  9. RSpec: allow() and expect() stubs
  10. Coverage configuration:
  11. Set threshold from input (default 80%)
  12. Configure reporters (JSON, LCOV, HTML)
  13. Exclude patterns (vendor, generated code)
  14. Research verification (2-4 sources):
  15. Check current best practices for chosen framework (accessed NOW_ET)
  16. Validate mocking patterns against official docs

Token budget: ≀6k tokens (includes retrieval + generation)


T3: Advanced Patterns (≀12k tokens)

Deep dive with property-based testing and fixtures:

  1. Property-based testing:
  2. Jest: fast-check integration
  3. PyTest: hypothesis strategies
  4. Go: testing/quick package
  5. JUnit: jqwik or QuickTheories
  6. RSpec: rantly gem
  7. Fixture management:
  8. Shared setup/teardown across tests
  9. Database seeding and cleanup
  10. Factory patterns for test data
  11. Parameterized tests:
  12. Jest: test.each()
  13. PyTest: @pytest.mark.parametrize
  14. Go: table-driven tests
  15. JUnit: @ParameterizedTest
  16. RSpec: shared examples
  17. Generate eval scenarios:
  18. Create 3-5 test cases in tests/evals_unit-testing-generator.yaml
  19. Include success, failure, and edge cases
  20. Full rationale document:
  21. Design decisions for mocking strategy
  22. Coverage threshold justification
  23. Framework-specific gotchas

Token budget: ≀12k tokens (includes research, generation, evals)


Decision Rules

Framework selection:
- If target_code has file extension β†’ auto-detect: .js/.ts β†’ Jest, .py β†’ PyTest, .go β†’ Go, .java β†’ JUnit, .rb β†’ RSpec
- If ambiguous β†’ prompt for explicit framework input

Mocking strategy thresholds:
- 0 external dependencies β†’ skip T2 mocking, stay in T1
- 1-3 dependencies β†’ T2 with explicit mocks
- 4+ dependencies β†’ T3 with dependency injection patterns

Abort conditions:
- target_code is unparseable or empty β†’ emit TODO and stop
- Framework not in supported list β†’ error with alternatives
- Coverage threshold >100 or <0 β†’ validation error


Output Contract

Required fields:

{
  test_files: [
    {
      path: string,          // e.g., "src/__tests__/service.test.js"
      content: string,        // Full test file code
      framework: string       // Jest|PyTest|Go|JUnit|RSpec
    }
  ],
  config: {
    file_name: string,       // e.g., "jest.config.js"
    content: string,         // Configuration code
    description: string      // What this configures
  },
  coverage_setup: {
    threshold: number,       // 0-100
    reporters: string[],     // ["json", "lcov", "text"]
    exclude_patterns: string[] // Globs to ignore
  },
  metadata: {
    generated_at: string,    // ISO-8601 timestamp
    token_tier: "T1"|"T2"|"T3",
    sources_consulted: [     // Only for T2+
      {
        title: string,
        url: string,
        accessed: string     // NOW_ET
      }
    ]
  }
}

Validation:
- All paths use forward slashes (portable)
- Code is syntactically valid for target framework
- Coverage threshold matches input or default


Examples

Input:

{
  "framework": "PyTest",
  "target_code": "class UserService:\n    def get_user(self, id): return db.query(User).get(id)",
  "test_type": "unit",
  "coverage_threshold": 90
}

Output (T2 with mocking):

# tests/test_user_service.py
import pytest
from unittest.mock import Mock, patch
from myapp.services import UserService

@pytest.fixture
def mock_db():
    return Mock()

def test_get_user_success(mock_db):
    # Arrange
    user_service = UserService(db=mock_db)
    mock_db.query.return_value.get.return_value = {"id": 1, "name": "Alice"}

    # Act
    result = user_service.get_user(1)

    # Assert
    assert result["id"] == 1
    mock_db.query.assert_called_once()

(Full output would include pytest.ini config and coverage setup; truncated for ≀30 line limit)


Quality Gates

Token budgets (enforced):
- T1: ≀2k tokens
- T2: ≀6k tokens
- T3: ≀12k tokens

Safety:
- No hardcoded credentials in test fixtures
- Mock external services (no live API calls in unit tests)
- Deterministic test data (no random values without seeds)

Auditability:
- All generated code includes framework version assumptions
- T2+ includes source links with access dates (NOW_ET)
- Mocking decisions documented in comments

Determinism:
- Same inputs β†’ same test structure
- Randomized tests use explicit seeds
- Date/time mocks for time-dependent code


Resources

Official Documentation (accessed 2025-10-26T02:31:24Z):
- Jest - Getting Started
- PyTest - Official Docs
- Go Testing Package
- JUnit 5 User Guide
- RSpec - Documentation

Mocking Libraries:
- Jest Mock Functions
- pytest-mock Plugin
- Mockito (Java)
- RSpec Mocks

Property-Based Testing:
- fast-check (Jest)
- Hypothesis (Python)
- testing/quick (Go)
- jqwik (JUnit)

Coverage Tools:
- Istanbul (Jest)
- Coverage.py (PyTest)
- go tool cover
- JaCoCo (Java)
- SimpleCov (Ruby)

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.