P
💻DeveloppementIntermediateAll AIs

Write Comprehensive Unit Tests

Generate an exhaustive unit test suite covering nominal cases, edge cases, and errors with appropriate mocks.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

You are an expert in Test-Driven Development (TDD) and software quality assurance. I need to write comprehensive unit tests for the following code written in [language] with the [e.g. Jest, Pytest, JUnit] testing framework:

[paste the code to test]

Context:

  • Testing framework: [e.g. Jest with TypeScript, Pytest, JUnit 5]
  • Mocking library: [e.g. jest.mock, unittest.mock, Mockito]
  • Target coverage: [e.g. 90% minimum]
  • Test style: [e.g. BDD with describe/it, or AAA (Arrange-Act-Assert)]

Generate a complete test suite that covers:

  1. Happy paths: normal usage scenarios where everything works as expected.
  2. Edge cases: null values, empty strings, empty arrays, negative numbers, maximum values.
  3. Error cases: expected exceptions, network errors, timeouts, malformed data.
  4. Mocks and stubs: mock external dependencies (databases, APIs, third-party services) with realistic implementations.
  5. Async tests: if the code is async, cover both resolved and rejected promises.

For each test, use descriptive names in the format 'should [expected behavior] when [condition]'. Include a comment explaining why each edge case is important to test.

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt is effective because it requests systematic coverage across the five most important test categories. By specifying the framework and mock library upfront, the AI produces directly usable code without requiring adaptation. The imposed naming convention ('should [behavior] when [condition]') ensures self-documenting tests that also serve as living documentation of expected code behavior. This is an essential practice in team projects. Requesting explanatory comments for edge cases transforms the tests into a pedagogical tool, helping less experienced developers understand why certain scenarios need testing, not just how.

Use Cases

Writing tests for existing codeTDD trainingIncreasing code coverage

Expected Output

A complete unit test suite with nominal cases, edge cases, errors, mocks, and descriptive names ready to run.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Pour maximiser l'efficacité, ajoute dans le prompt les valeurs exactes des cas limites (ex: `None, "", -1, 0, sys.maxsize`) et le chemin du module à mocker. Cela évite des tests génériques et assure des assertions précises.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementAdvancedAll AIs

Implement canary deployments

Roll out changes safely with canary

491
💻DeveloppementIntermediateAll AIs

Design a Complete REST API

Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.

846

Implement Clean Architecture in Practice

Implement Clean Architecture in practice with layers, ports and adapters, use cases, and unit tests without infrastructure.

883
💻DeveloppementIntermediateAll AIs

Sora Prompt for Generating a Database Schema

Sora, the visual generation model developed by OpenAI, offers interesting possibilities for creating visual representations of database schemas. Instead of working with traditional technical tools like dbdiagram.io or Lucidchart, Sora can generate entity-relationship (ER) diagrams, relational schemas, and data architecture visualizations as clear, professional images. This approach is particularly useful for presentations, technical documentation, or initial design phases where you want to quickly visualize database structure without using specialized tools. By crafting a precise prompt describing tables, relationships, and constraints, you can obtain a usable visual schema in seconds. In this guide, we provide an optimized prompt for Sora along with several variants tailored to your expertise level and project complexity.

531