Generate unit tests from a repository, ZIP, or code

Use this prompt to inspect a supplied repository, ZIP, or code sample, identify the project’s testing setup, generate focused unit tests, and report the actual execution result.

  • Outcome
    Produces focused unit-test code for the specified file, function, class, module, or component.
  • Use case
    Use when a repository, ZIP, or code sample needs new unit tests that follow its existing framework and conventions.
  • Output
    Returns the target test path, complete test code, the relevant test command, and the actual execution result.

Scope and best-fit use

Use this prompt to create unit tests for supplied project code. Use the separate test-coverage review workflow when the primary task is evaluating existing tests rather than writing new ones.

A repository, ZIP, or code sample needs unit tests

Use when the assistant should inspect the supplied project structure, identify its testing conventions, and add focused tests for specified code.

  • Project discovery
    Identify the language, test framework, runner, file structure, neighboring tests, and reusable test utilities from the supplied materials.
  • Test generation
    Create relevant tests for normal behavior, invalid input, boundaries, errors, state changes, and side effects.
  • Verification
    Run the narrowest supported test command when available and distinguish a test failure, blocked execution, and a test that was not run.

Inputs required

Provide the repository, ZIP, or relevant code, identify the target to test, and include expected behavior, a known bug, or project constraints when available.

  • Repository, ZIP, or code: The project materials required to identify the implementation, test framework, file structure, configuration, and existing testing conventions.
  • Target code: The file, function, class, module, or component for which unit tests should be generated.
  • Expected behavior or known bug: Requirements, expected results, failure conditions, or a bug to cover when available. If none are supplied, the prompt uses the code’s current observable behavior as the test basis.

Copy-ready prompt

Copy the prompt and replace the MATERIALS block with the repository, ZIP, or code, the target to test, and any available behavior or project constraints.

Generate unit tests for the supplied repository, ZIP, or code.

TASK:
Inspect the supplied materials and create focused unit tests for the specified code.

INSTRUCTIONS:
- Identify the language, test framework, test runner, file structure, and existing testing conventions from the supplied materials.
- Use neighboring tests as the primary reference for naming, setup, fixtures, mocks, helpers, and assertions.
- Use supplied requirements or expected behavior as the test basis. If none are supplied, test the code’s current observable behavior and state that this is the basis.
- Cover the relevant normal, invalid-input, boundary, error, state-change, and side-effect cases.
- Test observable behavior rather than private implementation details.
- Keep tests focused, fast, isolated, deterministic, and runnable in any order.
- Reuse existing project test utilities and isolate external dependencies with the project’s established mechanisms.
- Add the tests in the correct project location and avoid duplicating existing coverage.
- Limit changes to test files. If correct testing requires a production-code, configuration, or dependency change, report it before expanding the scope.
- If a required project detail cannot be determined from the supplied materials, ask one precise question before writing the tests.
- Run the narrowest supported test command when execution is available. Report only the actual result.

OUTPUT:
1. Target test file path
2. Complete test code
3. Test command
4. Execution result: Passed / Test failure / Execution blocked / Not run
5. Exact failure evidence or reason when the result is not Passed

MATERIALS:
"""
Repository, ZIP, or code:
[Attach or paste the materials.]

Target code:
[Identify the file, function, class, module, or component to test.]

Expected behavior or bug to cover:
[Add when available.]

Constraints:
[Add relevant project constraints.]
"""

Use this as a unit-test generation prompt

Provide access to the repository, ZIP, or relevant code and identify the target to test. Include neighboring tests when project-specific alignment matters.

Next steps

Use these related assets when the task is reviewing existing coverage, evaluating code quality, or applying stricter evidence controls.