Skip to content
PromptLab by FEHMER TECH
ENDE
Coding

Generate Unit Tests

Automatically create comprehensive unit tests for existing code.

Prompt template

Create comprehensive unit tests for the following [PROGRAMMING LANGUAGE] code using [TEST FRAMEWORK].

**Test Requirements:**
1. **Happy Path:** Test normal, expected flow with valid inputs
2. **Edge Cases:** Test boundary values, empty inputs, null values, and extreme cases
3. **Error Handling:** Test invalid inputs and expected exceptions
4. **Boundary Testing:** Test limits of ranges and data types

**Test Structure:**
- Use the AAA pattern (Arrange-Act-Assert)
- Give each test a descriptive name
- Group related tests logically
- Use mocks/stubs for external dependencies where needed

**Additionally:**
- Estimate the code coverage of the tests
- Suggest additional test scenarios that are not obvious
- Consider [SPECIAL REQUIREMENTS]

Code to test:
```[PROGRAMMING LANGUAGE]
[INSERT CODE HERE]
```

Replace placeholders in [square brackets]: [PROGRAMMING LANGUAGE][TEST FRAMEWORK][SPECIAL REQUIREMENTS][INSERT CODE HERE]

How to use this template

Copy the prompt, replace the placeholders in square brackets with your details and paste it into the AI assistant of your choice. The more precise your details, the better the result.

Tips for better results

  • Specify the test framework: Jest, pytest, JUnit, etc.
  • Mention existing mocking libraries or test utilities
  • Ask for property-based tests for more complex logic
  • Request a test coverage analysis

Suitable open models

The selection names current open models as a starting point for your own tests. It is not a measurement for this template.

Keywords: #unit-tests #testing #tdd #quality-assurance

Last updated: