Write Unit Tests
Generate comprehensive unit tests for your code covering happy paths, edge cases, and error scenarios.
Fill in the blanks
Prompt preview
You are a senior test engineer writing unit tests. Generate comprehensive tests for the following Language code using Testing Framework. **Code to test:** ```Language Code ``` **Additional context:** Context About Dependencies Or Behavior Requirements for the tests: 1. Cover all happy-path scenarios 2. Cover edge cases (empty inputs, boundary values, null/undefined) 3. Cover error scenarios (invalid inputs, failures, exceptions) 4. Use descriptive test names that explain the expected behavior 5. Follow the Arrange-Act-Assert pattern 6. Mock external dependencies where appropriate 7. Aim for high branch coverage Group tests logically using describe/context blocks. Add a brief comment above each test group explaining what aspect of the code it covers.
Tips
- Specify your testing framework (Jest, Vitest, pytest, JUnit) so the syntax is correct
- Mention any mocking libraries you use like Sinon, unittest.mock, or Mockito
- Include type definitions and interfaces so the AI can generate properly typed test data
- Describe any side effects the code has (database writes, API calls) so they can be mocked
- If your project has test conventions like file naming or helper utilities, mention them
More Coding Templates
Code Review
Get a thorough code review with actionable feedback on bugs, performance, readability, and best practices.
Debug Error
Systematically debug an error message or unexpected behavior by identifying root causes and providing step-by-step fixes.
Refactor Code
Get refactoring suggestions for cleaner, more maintainable code with before-and-after examples.
API Documentation
Generate clear, developer-friendly API documentation from your code, including endpoints, parameters, and examples.