Testing Best Practices Cursor Rules
Universal Cursor rules for writing better tests: test structure, naming conventions, test isolation, and TDD practices.
- Follow the AAA pattern: Arrange, Act, Assert — one assertion per concept - Name tests as: "given [context], when [action], then [expectation]" - Test behavior, not implementation; avoid mocking everything - Use test fixtures and factories for data setup; avoid magic values - Keep unit tests fast (<10ms) by mocking I/O; use integration tests for real DB - Test error paths and edge cases, not just the happy path - Never put business logic in tests; keep them simple and obvious - Run tests in CI on every PR; measure and track coverage trends
How to use with Cursor
Create a `.cursorrules` file in your project root and paste these rules. Cursor reads this automatically on every AI interaction.
Related Rules
Python Cursor Rules
Best Cursor AI coding rules for Python development. Enforce type hints, PEP 8, Pythonic patterns, and modern Python best practices in your .cursorrules file.
TypeScript Cursor Rules
Cursor rules for TypeScript: enforce strict mode, eliminate any types, and write type-safe code with these .cursorrules configurations.
React Cursor Rules
Cursor rules for React: component patterns, hooks best practices, performance optimization, and clean state management conventions.
Next.js Cursor Rules
Cursor rules for Next.js App Router: server components, data fetching, routing, and deployment best practices.