0
0
Cypresstesting~5 mins

Test naming conventions in Cypress

Choose your learning style9 modes available
Introduction

Good test names help everyone understand what the test checks. They make finding and fixing problems faster.

When writing a new test to describe what it does clearly
When reviewing tests to understand their purpose quickly
When debugging to find which test failed and why
When sharing tests with teammates for easy collaboration
When organizing tests to keep the project clean and readable
Syntax
Cypress
describe('Feature or module name', () => {
  it('should do something expected', () => {
    // test steps
  })
})

Use describe to group related tests by feature or page.

Use it to name individual test cases with clear, simple language.

Examples
This test checks that the login page shows an error when the password is wrong.
Cypress
describe('Login Page', () => {
  it('should show error for invalid password', () => {
    // test code
  })
})
This test confirms that adding an item to the cart works as expected.
Cypress
describe('Shopping Cart', () => {
  it('adds item to cart successfully', () => {
    // test code
  })
})
This test verifies that the user can update their email address.
Cypress
describe('User Profile', () => {
  it('updates user email address', () => {
    // test code
  })
})
Sample Program

This test suite checks the search feature. Each test name clearly says what it tests, making it easy to understand and maintain.

Cypress
describe('Search Feature', () => {
  it('returns results for valid query', () => {
    cy.visit('/search')
    cy.get('input[aria-label="Search input"]').type('cypress testing{enter}')
    cy.get('.results').should('contain.text', 'cypress testing')
  })

  it('shows no results message for empty query', () => {
    cy.visit('/search')
    cy.get('input[aria-label="Search input"]').clear().type('{enter}')
    cy.get('.no-results').should('be.visible').and('contain.text', 'No results found')
  })
})
OutputSuccess
Important Notes

Keep test names short but descriptive enough to explain the test purpose.

Use present tense and active voice, like 'adds item' or 'shows error'.

Avoid technical details or implementation in test names; focus on behavior.

Summary

Clear test names improve communication and debugging.

Use describe and it blocks to organize and name tests.

Write names that anyone can understand without extra explanation.