How to Run Only One Test in Cypress Quickly and Easily
To run only one test in Cypress, add
.only to the test or describe block, like it.only() or describe.only(). This tells Cypress to run just that test or group, skipping all others.Syntax
Use .only after it or describe to run a single test or test suite.
it.only('test name', () => { ... })runs only this test.describe.only('suite name', () => { ... })runs all tests inside this suite only.
This helps focus on one test during development or debugging.
javascript
describe.only('My Test Suite', () => { it('runs this test only', () => { // test code here }) }) // or it.only('runs only this test', () => { // test code here })
Example
This example shows how to run only one test out of many using it.only. Only the marked test will run, and others will be skipped.
javascript
describe('Math operations', () => { it('adds numbers', () => { expect(1 + 1).to.equal(2) }) it.only('subtracts numbers', () => { expect(5 - 3).to.equal(2) }) it('multiplies numbers', () => { expect(2 * 3).to.equal(6) }) })
Output
Running: subtracts numbers
โ subtracts numbers (passed)
Tests: 1 passed, 0 failed, 0 skipped
Common Pitfalls
Common mistakes when running a single test in Cypress include:
- Forgetting to remove
.onlyafter debugging, causing other tests to be skipped unintentionally. - Using
.onlyon multiple tests or suites, which runs all marked tests but not others. - Confusing
it.onlywithit.skip, which skips tests instead of running only one.
Always double-check your test files before committing.
javascript
describe('Example Suite', () => { it.only('test one', () => { // runs }) it.only('test two', () => { // also runs because of multiple .only }) it('test three', () => { // skipped }) })
Output
Running: test one
Running: test two
Tests: 2 passed, 0 failed, 1 skipped
Quick Reference
| Command | Description |
|---|---|
| it.only() | Run only this single test |
| describe.only() | Run only this test suite and its tests |
| it.skip() | Skip this test |
| describe.skip() | Skip this test suite |
| Remove .only | Run all tests normally |
Key Takeaways
Use .only on it or describe to run just one test or suite in Cypress.
Remove .only after debugging to avoid skipping other tests.
Multiple .only run all marked tests but skip others.
it.skip and describe.skip skip tests instead of running only one.
Use .only to speed up development by focusing on a single test.