Unit testing framework

From aj-geddes/useful-ai-prompts · View interactive version

Unit testing framework is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Write comprehensive unit tests with high coverage using testing frameworks like Jest, pytest, JUnit, or RSpec. Use when writing tests for functions, classes, components, or establishing testing standards.

How to use this skill

Skill file

Unit Testing Framework

Table of Contents

Overview

Write effective unit tests that are fast, isolated, readable, and maintainable following industry best practices and AAA (Arrange-Act-Assert) pattern.

When to Use

Quick Start

Minimal working example:

// Jest/JavaScript example
describe("UserService", () => {
  describe("createUser", () => {
    it("should create user with valid data", async () => {
      // Arrange - Set up test data and dependencies
      const userData = {
        email: "john@example.com",
        firstName: "John",
        lastName: "Doe",
      };
      const mockDatabase = createMockDatabase();
      const service = new UserService(mockDatabase);

      // Act - Execute the function being tested
      const result = await service.createUser(userData);

      // Assert - Verify the outcome
      expect(result.id).toBeDefined();
      expect(result.email).toBe("john@example.com");
      expect(mockDatabase.save).toHaveBeenCalledWith(
        expect.objectContaining(userData),
      );
    });
  });
});

Reference Guides

Detailed implementations in the references/ directory:

| Guide | Contents |

|---|---|

| Test Structure (AAA Pattern) | Test Structure (AAA Pattern) |

| Test Cases by Language | Test Cases by Language |

| Mocking & Test Doubles | Mocking & Test Doubles |

| Testing Async Code | Testing Async Code, Test Coverage |

| Testing Edge Cases | Testing Edge Cases |

| Example: Complete Test Suite | import { UserService } from "./user-service"; |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.