Przejdź do treści
Biblioteka skilli
Programowanie · Testowanie

generating-unit-tests

/generating-unit-tests

Generuje testy jednostkowe z kodu źródłowego, obejmujące ścieżki typowe, przypadki brzegowe i warunki błędów, dla funkcji, klas i modułów.

Licencja
MIT
Ostatnia zmiana repozytorium
26.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
4
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
5
Przestarzałość

Brak sygnałów. Repozytorium zmienione 26.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Generuje testy jednostkowe z kodu źródłowego, obejmujące ścieżki typowe, przypadki brzegowe i warunki błędów, dla funkcji, klas i modułów.

Wyzwalacze z opisu

generate unit testscreate tests foradd test coverage
Oryginalny opis (EN)

Test automatically generate comprehensive unit tests from source code covering happy paths, edge cases, and error conditions. Use when creating test coverage for functions, classes, or modules. Trigger with phrases like "generate unit tests", "create tests for", or "add test coverage".

Jak działa

  1. Overview
  2. Prerequisites
  3. Instructions
  4. Output
  5. Error Handling
  6. Examples
  7. Resources
Sekcje z nagłówków SKILL.md, w oryginale · 112 linii, 647 słów
Podgląd SKILL.md
---
name: generating-unit-tests
description: 'Test automatically generate comprehensive unit tests from source code
  covering happy paths, edge cases, and error conditions.

  Use when creating test coverage for functions, classes, or modules.

  Trigger with phrases like "generate unit tests", "create tests for", or "add test
  coverage".

  '
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(test:unit-*)
version: 1.21.0
author: Jeremy Longshore <jeremy@intentsolutions.io>
license: MIT
tags:
- testing
- unit-tests
compatibility: Designed for Claude Code
---
# Unit Test Generator

## Overview

Automatically generate comprehensive unit tests from source code analysis covering happy paths, edge cases, boundary conditions, and error handling. Supports Jest, Vitest, Mocha (JavaScript/TypeScript), pytest (Python), JUnit 5 (Java), and Go testing with testify.

## Prerequisites

- Testing framework installed and configured (`jest`, `vitest`, `pytest`, `junit-jupiter`, or Go `testing`)
- Source code with clear function signatures, type annotations, or JSDoc comments
- Test directory structure established (`__tests__/`, `tests/`, `spec/`, or `*_test.go`)
- Mocking library available (`jest.mock`, `unittest.mock`, `Mockito`, or `gomock`)
- Package scripts configured to run tests (`npm test`, `pytest`, `go test`)

## Instructions

1. Scan the codebase with Glob to locate source files that lack corresponding test files (e.g., `src/utils/parser.ts` without `__tests__/parser.test.ts`).
2. Read each untested source file and extract:
   - All exported functions and class methods with their signatures.
   - Parameter types, return types, and thrown exceptions.
   - External dependencies (imports from other modules, third-party libraries, I/O).
   - Pure vs. impure function classification.
3. For each function, generate test cases in these categories:
   - **Happy path**: Valid inputs producing expected outputs (at least 2 cases).
   - **Edge cases**: Empty strings, empty arrays, zero, negative numbers, `null`, `undefined`, maximum values.
   - **Error conditions**: Invalid types, missing required fields, network failures, permission errors.
   - **Boundary values**: Off-by-one, integer overflow, string length limits.
4. Create mock declarations for all external dependencies:
   - Database calls return predictable fixture data.
   - HTTP clients return canned responses with configurable status codes.
   - File system operations use in-memory buffers or temp directories.
5. Write the test file following project conventions:
   - Match the existing test file naming pattern (`*.test.ts`, `*.spec.js`, `test_*.py`).
   - Group tests in `describe`/`context` blocks by function name.
   - Use `beforeEach`/`afterEach` for setup and teardown.
   - Include inline comments explaining non-obvious test rationale.
6. Run the generated tests to verify they pass, then check coverage to confirm the target function is fully exercised.
7. Report coverage gaps and suggest additional test cases for uncovered branches.

## Output

- Test files placed alongside source files or in the project's test directory
- Mock/stub files for external dependencies
- Coverage report showing line, branch, and function coverage for tested modules
- List of remaining coverage gaps with suggested test cases

## Error Handling

| Error | Cause | Solution |
|-------|-------|---------|
| `Cannot find module` on import | Test file path does not match project module resolution | Check `tsconfig.json` paths and `moduleNameMapper` in Jest config |
| Mock not intercepting calls | Mock defined after module import caches the real implementation | Move `jest.mock()` calls to the top of the file before any imports |
| Async test timeout | Promise never resolves due to missing `await` or unhandled rejection | Add `await` before async calls; increase timeout with `jest.setTimeout()` |
| Tests pass alone but fail together | Shared mutable state leaking between tests | Reset state in `afterEach`; avoid module-level variables; use `jest.isolateModules()` |
| Snapshot mismatch on first run | No existing snapshot baseline | Run with `--updateSnapshot` on first execution to create the baseline |

## Examples

**Jest test for a string utility:**

```typescript
import { slugify } from '../src/utils/slugify';

describe('slugify', () => {
  it('converts spaces to hyphens', () => {
    expect(slugify('hello world')).toBe('hello-world');
  });
  it('lowercases all characters', () => {
    expect(slugify('Hello World')).toBe('hello-world');
  });
  it('removes special characters', () => {
    expect(slugify('hello@world!')).toBe('helloworld');
  });
  it('handles empty string', () => {
    expect(slugify('')).toBe('');
  });
  it('trims leading and trailing whitespace', () => {
    expect(slugify('  spaced  ')).toBe('spaced');
  });
});
```

**pytest test for a data validator:**

```python
import pytest
from myapp.validators import validate_email

class TestValidateEmail:
    def test_accepts_valid_email(self):
        assert validate_email("user@example.com") is True

    def test_rejects_missing_at_sign(self):
        assert validate_email("userexample.com") is False

    def test_rejects_empty_string(self):
        assert validate_email("") is False

    def test_rejects_none(self):
        with pytest.raises(TypeError):
            validate_email(None)
```

## Resources

- Jest documentation: https://jestjs.io/docs/getting-started
- Vitest documentation: https://vitest.dev/guide/
- pytest documentation: https://docs.pytest.org/
- JUnit 5 User Guide: https://junit.org/junit5/docs/current/user-guide/
- Go testing package: https://pkg.go.dev/testing
- AAA pattern (Arrange-Act-Assert):
Pliki w paczce (4)
  • SKILL.md 6 KB
  • assets/README.md 1 KB
  • references/README.md 1 KB
  • scripts/README.md 1 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · jeremylongshore/tons-of-skills-marketplace100MIT
HelixDevelopment/agent100MIT

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki c5b16bb754c2 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100unit-test-generator
    Generuje testy jednostkowe dla funkcji, klas i modułów w Pythonie (pytest, unittest) i Javie (JUnit, TestNG): ścieżki szczęśliwe, przypadki brzegowe i błędy, w stylu istniejących testów.
  • 100unit-testing-test-generate
    Generuje rozbudowane testy jednostkowe w różnych językach, z naciskiem na pokrycie kodu i przypadki brzegowe.
  • 100test-writer
    Pisze testy jednostkowe dla dowolnej funkcji: ścieżka szczęśliwa, przypadki brzegowe i błędy, także w praktyce TDD.
  • 84generate-tests
    Generuje testy jednostkowe, integracyjne i e2e dla kodu, na przykład dla funkcji, endpointów API czy przepływu zakupowego.
  • 100test-generator
    Pisze testy jednostkowe i integracyjne dla istniejącego kodu: ścieżki poprawne, błędy i wartości graniczne, w stylu projektu.
  • 100unit-testing
    Pisze i aktualizuje testy jednostkowe dla nowego lub zmienionego kodu, uruchamia je z pokryciem i naprawia błędy.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.