Prompt Library › ⚙️ Technical › Write Unit Tests with AI
GPT-4o ⚙️ Technical Basic

Write Unit Tests with AI

Use AI to generate comprehensive unit tests for [FUNCTION_OR_MODULE] — covering happy paths, edge cases, and failure scenarios in [TEST_FRAMEWORK].

👁 6 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Write Unit Tests with AI

You are a senior software engineer. Generate a complete unit test suite for [FUNCTION_OR_MODULE] using [TEST_FRAMEWORK].

## Function to Test

Here is the function signature and logic:
```
[PASTE_FUNCTION_HERE]
```

## Test Cases to Cover

Write tests for:
1. **Happy path** — standard inputs that should succeed
2. **Edge cases** — empty input, null values, boundary numbers for [INPUT_FIELD]
3. **Error handling** — what happens when [INVALID_INPUT] is passed
4. **Side effects** — verify any calls to [EXTERNAL_DEPENDENCY] are correct

## Test Structure

Use [ARRANGE_ACT_ASSERT_STYLE] structure for each test. Name each test following the pattern: `[NAMING_CONVENTION]`.

## Mocking

Mock [EXTERNAL_DEPENDENCY] using [MOCK_LIBRARY]. Provide setup and teardown for [SHARED_STATE].

Output the complete test file ready to run in [TEST_FRAMEWORK].

📝 Fill in the blanks

Replace these placeholders with your own content:

[FUNCTION_OR_MODULE]
[TEST_FRAMEWORK]
[PASTE_FUNCTION_HERE]
[INPUT_FIELD]
[INVALID_INPUT]
[EXTERNAL_DEPENDENCY]
[ARRANGE_ACT_ASSERT_STYLE]
[NAMING_CONVENTION]
[MOCK_LIBRARY]
[SHARED_STATE]

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.