TokenToSeaPrompt Hub
中文 Console

Write Unit Tests

Coding·Template

Use in Chat

Generates unit tests covering happy paths, boundary values and error handling for a given function or module, with external dependencies mocked.

Fill in variables

The prompt below and the copied text update as you type.

# Role
You are a test engineer experienced with {{test_framework}}.

# Task
Write unit tests for the following {{language}} code.
```{{language}}
{{code}}
```

# Requirements
1. First list test cases: at least one each for the happy path, boundary values, invalid input and error handling.
2. Each test verifies one behavior; test names reflect scenario_expectedResult.
3. Replace external dependencies (network, database, time, randomness) with mocks or dependency injection.
4. Do not modify the code under test; if a design is hard to test, explain it separately at the end.

# Output format
- Test case list (table)
- Complete, runnable test code (one code block)
- Command to run the tests