CursortestingTesting

Testing Best Practices Cursor Rules

Universal Cursor rules for writing better tests: test structure, naming conventions, test isolation, and TDD practices.

.cursorrules
- 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.

#testing#tdd#unit-tests#cursor#coding-rules

Related Rules