Create Comprehensive Unit Tests for Any Function
Generate comprehensive unit tests for any function with edge cases, mocking, and best practices. Perfect for developers wanting thorough test coverage.
Prompt Template
Variables to Customize
[PROGRAMMING_LANGUAGE] The programming language of the function
Example: Python
[FUNCTION_CODE] The complete function code to create tests for
Example: def calculate_discount(price, discount_percent, customer_type='regular'): if price <= 0: raise ValueError('Price must be positive') if discount_percent < 0 or discount_percent > 100: raise ValueError('Discount must be between 0 and 100') base_discount = price * (discount_percent / 100) if customer_type == 'premium': base_discount *= 1.1 return round(price - base_discount, 2)
[TESTING_FRAMEWORK] The testing framework to use
Example: pytest
[ADDITIONAL_REQUIREMENTS] Any specific testing requirements or constraints
Example: Include parametrized tests and ensure all branches are covered
Example Output
Pro Tips for Best Results
- Always include the function's imports and dependencies in your prompt for accurate test generation
- Specify the exact testing framework and version if you have specific syntax requirements
- Ask for parametrized tests when you need to test multiple input combinations efficiently
- Include any existing test patterns or naming conventions used in your codebase
- Request coverage reports or mention specific coverage targets if code coverage is important
Tags
Want 500+ Expert Prompts?
Get the Premium Prompt Pack — organized, tested, and ready to use.
Get it for $29Related Prompts You Might Like
Debug Async JavaScript Issues
You are an expert JavaScript debugger specializing in asynchronous code issues. I need help debugging async JavaScript p...
Implement Rate Limiting for APIs
You are an expert backend engineer specializing in API security and performance optimization. I need you to implement a ...
Debug Network Request Failures
You are an expert network debugging specialist. I need help troubleshooting a network request failure. Please analyze th...
Explain Complex Code Snippet
You are an expert programmer and teacher. I need help understanding a complex code snippet. Please provide a comprehensi...
Implement API Pagination System
I need to implement pagination for a REST API endpoint. Please provide a complete implementation with the following requ...
Generate Environment Configuration Files
You are an expert DevOps engineer tasked with creating environment configuration files. Generate comprehensive configura...