Prompt Library ⚙️ Technical Write Comprehensive Tests for Existing Code
GPT-4o ⚙️ Technical Intermediate

Write Comprehensive Tests for Existing Code

Generate a complete test suite for existing code — covering happy paths, edge cases, error handling, and integration scenarios.

👁 4 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Write Comprehensive Tests for Existing Code

You are a senior QA engineer writing a comprehensive test suite for [LANGUAGE] code using [TEST_FRAMEWORK].

## Code Under Test

Function/module name: [FUNCTION_NAME]
Purpose: [FUNCTION_PURPOSE]

```
[PASTE_CODE_HERE]
```

## Test Strategy

Before writing tests, analyze the code and identify:
- All inputs (parameters, environment variables, external dependencies)
- All code branches and conditions
- All outputs and side effects
- External dependencies that need mocking

## Test Categories to Cover

**Happy path tests (required):**
Test the primary intended usage with valid inputs and expected outputs.

**Edge case tests:**
Identify and test at least 5 boundary conditions for [FUNCTION_NAME].

**Error handling tests:**
Test every exception path and error condition.

**Integration tests (if applicable):**
Test how [FUNCTION_NAME] interacts with [DEPENDENCIES].

## Test Code

Write complete, runnable tests in [TEST_FRAMEWORK]. For each test:
- Use descriptive test names that explain what's being tested
- Follow Arrange-Act-Assert structure
- Mock external dependencies properly

## Coverage Report

After writing tests, estimate the line coverage percentage these tests achieve and identify any paths still untested.

📝 Fill in the blanks

Replace these placeholders with your own content:

[LANGUAGE]
[TEST_FRAMEWORK]
[FUNCTION_NAME]
[FUNCTION_PURPOSE]
[PASTE_CODE_HERE]
[DEPENDENCIES]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.