In this categoryCursor ยท 26
- How to Install Cursor and Import VS Code Settings (6 Minutes)Start
- Cursor Setup Guide: From Install to Your First AI Edit
- How to Set Up Project Rules in the .cursor/rules Folder
- How to Set Up Codebase Indexing in Cursor
- How to Enforce Project Conventions with Cursor Rules
- How to Write a Team Rule That Applies Only to Certain Files
- How to Migrate a Legacy .cursorrules File to the New Rules Folder
- How to Use Cursor Rules to Guide AI Edits
- How to Set Project Rules in Cursor
- How to Add a .cursorrules File to Steer Cursor
- How to Customize Cursor Keyboard Shortcuts
- How to Edit Multiple Files at Once with Cursor Composer
- How to Use Cursor Tab Completion Effectively
- How to Edit Code Inline with Cmd+K in Cursor
- How to Add Context to Cursor Chat with @ Mentions
- How to Choose and Switch AI Models in Cursor
- How to Add Library Docs as Context with @Docs in Cursor
- How to Generate and Maintain Tests with Cursor Composer
- How to Undo a Composer Change with Checkpoints in Cursor
- How to Use Cursor Agent Mode to Build a Feature End to End
- How to Connect an MCP Server to Cursor
- How to Refactor Across Your Whole Codebase in Cursor
- How to Query Your Database from Cursor with a Postgres MCP Server
- How to Let Cursor Run Commands Automatically (and Keep It Safe)
- How to Build a Full Feature Across Frontend and Backend with Composer
- How to Debug an MCP Server That Will Not Connect in Cursor
How to Generate and Maintain Tests with Cursor Composer
Have Composer write a test file for a module and update it across files when the implementation changes.
Composer is good at writing tests because it can read the implementation, the existing test setup, and your conventions all at once. Better still, when you later change the implementation, it can update the test file in the same pass. This guide creates a test file for a module and then keeps it in sync after a signature change.
- A test runner already configured (Jest, Vitest, or similar)
- A module you want covered
- One existing test file Composer can copy the style from
Give Composer the module and a sample test
Add both the module under test and one existing test file with @. The sample test teaches Composer your import paths, assertion style, and naming so the new tests match the rest of the suite.
@src/lib/price.ts @src/lib/tax.test.ts
Write a test file for price.ts following the style of tax.test.ts.
Cover the happy path, a zero quantity, and a negative price error.Run the new tests
Accept the new file and run the suite. If a generated test fails, that is useful information: either the test is wrong or it found a real bug. Read the failure before assuming the test is at fault.
Keep tests in sync after a change
When you change a function signature, ask Composer to update the implementation and its tests together. Because it edits both files in one diff, the tests do not drift out of date.
calcPrice should take an options object { unit, qty, discount }.
Update price.ts and price.test.ts together. Add a test for discount.Result: a new test file written in your house style, and a workflow where signature changes update both the code and its tests in a single reviewable diff.
Watch related tutorials
12:08
33:42
41:18
28:05
3:12
26:54New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.