Skip to main content
AIPromptIndex
Cursor Coding intermediate

Cursor Test Writer

Added Apr 2, 2026

You are a test engineering specialist. Write comprehensive tests for the following [LANGUAGE] code using [TEST_FRAMEWORK]. The code implements [FUNCTIONALITY] in a [PROJECT_TYPE] project. [CODE_BLOCK] Generate tests covering these categories: Happy Path tests (expected inputs producing expected outputs), Edge Cases (boundary values, empty inputs, null/undefined values, maximum limits), Error Handling (invalid inputs, network failures, timeout scenarios), Integration Points (how this code interacts with dependencies), and Regression Guards (tests that would catch common bugs in this type of code). For each test, include a descriptive test name following the pattern 'should [expected behavior] when [condition]', arrange-act-assert structure with clear separation, meaningful assertion messages, and appropriate use of mocks, stubs, or fixtures for external dependencies. Group related tests in describe blocks. Include setup and teardown helpers where needed. Aim for at least [COVERAGE_TARGET] code coverage across all branches.
0
Share
Try in Cursor

About This Prompt

This prompt generates comprehensive test suites that go far beyond basic happy-path testing. It produces tests organized into logical categories covering edge cases, error handling, integration points, and regression scenarios that developers often miss. Each test follows the arrange-act-assert pattern with descriptive naming conventions that serve as living documentation. The prompt handles mock setup, fixture creation, and test organization so you get a production-ready test file. This is invaluable for developers who know they should write more tests but struggle with identifying what to test, and for teams looking to increase their code coverage systematically.

Variables to Customize

[LANGUAGE]

Programming language of the code to test

Example: TypeScript

[TEST_FRAMEWORK]

Testing framework to use

Example: Jest with React Testing Library

[FUNCTIONALITY]

What the code does

Example: a shopping cart service with add, remove, and calculate total operations

[PROJECT_TYPE]

Type of application

Example: e-commerce React application

[CODE_BLOCK]

The code to write tests for

Example: // paste your code here

[COVERAGE_TARGET]

Target code coverage percentage

Example: 90%

Tips for Best Results

  • Include your actual code for the most accurate and relevant test generation
  • Focus on testing behavior rather than implementation details for more resilient tests
  • Use the generated tests as a starting point and add domain-specific edge cases you know about

Example Output

describe('ShoppingCartService', () => {
  let cart: ShoppingCartService;
  let mockProductRepo: jest.Mocked<ProductRepository>;

  beforeEach(() => {
    mockProductRepo = createMockProductRepo();
    cart = new ShoppingCartService(mockProductRepo);
  });

  describe('addItem', () => {
    it('should add a new item with quantity 1 when item is not in cart', async () => {
      // Arrange
      const product = createTestProduct({ id: '1', price: 29.99 });
      mockProductRepo.findById.mockResolvedValue(product);

      // Act
      await cart.addItem('1');

      // Assert
      expect(cart.getItems()).toHaveLength(1);
      expect(cart.getItems()[0].quantity).toBe(1);
    });

    it('should increment quantity when adding an existing item', ...
    it('should throw InvalidProductError when product ID does not exist', ...
testing unit-tests test-driven-development code-quality software-engineering

Get the Best AI Prompts Weekly

Curated prompts, tips, and guides delivered to your inbox every week. Free.