Cursor AI Testing Patterns
БесплатноБез исполняемых скриптовНе проверенEffective test automation patterns with Cursor AI IDE including Composer for test suite generation, Cmd+K for inline test edits, Chat for test debugging…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
Cursor AI Testing Patterns Skill
You are an expert in using Cursor AI IDE for test automation. When the user asks you to generate tests with Cursor, configure Cursor rules for testing, use Composer for multi-file test generation, or optimize Cursor workflows for QA, follow these detailed instructions.
Core Principles
- Codebase-aware generation -- Cursor indexes your entire codebase. Reference files, functions, and patterns using @mentions to give the AI full context for test generation.
- Rules for consistent quality -- Configure .cursorrules to enforce testing conventions, naming patterns, and framework preferences across all AI-generated tests.
- Composer for multi-file operations -- Use Cursor Composer for generating test suites that span multiple files: page objects, fixtures, helpers, and test specs.
- Cmd+K for surgical edits -- Use inline editing (Cmd+K) for targeted changes: adding a test case, fixing an assertion, or refactoring a single test function.
- Chat for investigation -- Use Cursor Chat with @codebase to understand existing test patterns before generating new ones. Ask it to explain failures.
- Apply from Chat -- When Chat suggests code, use the Apply button to directly insert or replace code in your editor rather than copy-pasting.
- Iterative test development -- Generate a basic test suite first, run it, then use Cursor to fix failures and add edge cases based on execution results.
Project Structure
project/
.cursorrules # Testing conventions
.cursor/
rules/
testing.mdc # Testing-specific rules
src/
services/
user-service.ts
user-service.test.ts
components/
LoginForm.tsx
LoginForm.test.tsx
tests/
e2e/
login.spec.ts
checkout.spec.ts
fixtures/
test-data.ts
helpers/
test-utils.ts
Cursor Rules for Testing
<!-- .cursorrules -->
# Testing Rules
## Test Framework
- Use vitest for all unit and integration tests
- Use Playwright for E2E tests
- TypeScript strict mode in all test files
## Test Conventions
- Follow Arrange-Act-Assert (AAA) pattern
- Name tests: "should [expected behavior] when [condition]"
- Group related tests in describe blocks
- One assertion focus per test (multiple asserts allowed if testing same behavior)
- Always include edge cases: null, undefined, empty values, boundary conditions
- Always include error/failure test cases
## Mocking
- Use vi.mock() for module mocking
- Use vi.fn() for function mocking
- Use vi.spyOn() for spying on existing methods
- Reset mocks in beforeEach with vi.clearAllMocks()
- Never mock the module under test
## Assertions
- Prefer specific assertions: toBe, toEqual, toContain over toBeTruthy
- Use toThrow for error testing
- Use resolves/rejects for async assertions
- Include meaningful error messages in assertions
## File Organization
- Colocate tests with source files: foo.ts -> foo.test.ts
- E2E tests in tests/e2e/
- Shared test utilities in tests/helpers/
- Test fixtures in tests/fixtures/
## Do Not
- Use any type in test files
- Use setTimeout for async waiting
- Write tests that depend on execution order
- Hard-code API URLs or credentials
- Skip tests without a TODO comment explaining why
Composer Workflows for Test Generation
// Workflow 1: Generate comprehensive test suite with Composer
// Prompt: "Generate a complete test suite for @user-service.ts with vitest.
// Include unit tests for all public methods, mock the database dependency,
// test both success and error paths, and follow the patterns in @user-service.test.ts"
// Result: Cursor generates the full test file considering both files
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { UserService } from './user-service';
// Cursor reads the actual implementation to create accurate mocks
vi.mock('../db/connection', () => ({
db: {
select: vi.fn(),
insert: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
},
}));
import { db } from '../db/connection';
describe('UserService', () => {
let service: UserService;
beforeEach(() => {
service = new UserService();
vi.clearAllMocks();
});
// Cursor generates tests for each public method found in the source
describe('findById', () => {
it('should return user when found', async () => {
const mockUser = { id: '1', name: 'Alice', email: '[email protected]' };
vi.mocked(db.select).mockResolvedValueOnce([mockUser]);
const result = await service.findById('1');
expect(result).toEqual(mockUser);
});
it('should return null when user not found', async () => {
vi.mocked(db.select).mockResolvedValueOnce([]);
const result = await service.findById('nonexistent');
expect(result).toBeNull();
});
it('should throw when database error occurs', async () => {
vi.mocked(db.select).mockRejectedValueOnce(new Error('DB
Установить Cursor AI Testing Patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Cursor AI Testing Patterns?
Effective test automation patterns with Cursor AI IDE including Composer for test suite generation, Cmd+K for inline test edits, Chat for test debugging, codebase-aware test generation, and rules configuration for testing conventions.
Как установить скилл Cursor AI Testing Patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Cursor AI Testing Patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic