Skip to content
Independent notebook · software, testing, and open source No ads · no sponsored posts · no affiliate links
Soham Parekh software notebook

Journal / June 29, 2020

Cypress and the Case for Boring Test Setup

What two months of writing end to end tests in Cypress changed about the way I start a test suite.

Written by Soham Parekh

Published June 29, 2020

All tags

Test setup is usually where enthusiasm goes to die. You install a runner, choose an assertion library, add a reporter, wire up mocks, and then discover that each piece has its own configuration file. By the time the first test runs, the test itself feels like an afterthought.

Cypress takes a different position. It bundles the runner, assertions, network control, and a debugger into one product. That is not a small convenience. It changes the emotional shape of starting a suite.

The setup tax

Every testing stack charges a setup tax. Some charge it up front, in configuration. Others charge it later, when the pieces stop agreeing with each other. Cypress front loads less of that cost because the pieces are designed together. You install one package, open the runner, and write a test.

The price is that you are working inside Cypress's opinions. For a new project, that is often a good trade. For a project with an established pipeline, it deserves a careful look.

Documentation as part of the product

The best developer tools explain the reasoning behind their defaults. Cypress does that well. Its guides talk about how to select elements, how to avoid brittle waits, and how to structure a test so that a failure points at a cause. Reading those guides saved me from writing tests that passed for the wrong reason.

Start with one small test

Before recommending a tool, I like to put it on something small and real. I added a test to this site: open the home page, follow the link to the journal, and check that an entry appears. The whole thing took less time than a coffee break, and the runner recorded the run without extra setup.

That first test is not impressive. That is the point. A tool that makes the boring first test easy is more likely to be used for the second and third tests.

Page objects and readable steps

Page objects are an old idea, and they still work. Put the selectors and actions for a page in one place, then let the test describe a journey instead of a pile of DOM queries. Cypress fits that pattern without much ceremony.

Gherkin can help when non developers need to read the scenarios. The catch is that the English layer only helps if the steps underneath stay honest. A readable scenario wrapped around a fragile test is still a fragile test.

Selectors that survive a refactor

The most common source of test churn is a selector that depended on a class name or a DOM position. Testing Library style queries push you toward the text and roles a user would encounter, which makes the test more durable and more meaningful. It is not a complete answer, but it is a better default than reaching for the first div on the page.

Debugging with the runner beside you

The Cypress runner keeps a snapshot of each step. You can move through the command log, inspect the DOM at that moment, and see what the application looked like when the assertion ran. That is a different experience from reading a stack trace after the process has already exited.

Where Cypress did not fit

At the time, legacy browser support was the main gap, and the communication between the Node process and the browser could create failures that were hard to reproduce outside a specific CI environment. Those are not reasons to dismiss the tool. They are reasons to test it against your own pipeline before you commit.

Field note

Start with one test that proves the page loads. Then add the second. A suite is a habit, not a launch event.

Reference shelf

Primary documentation and project pages behind this entry.

A short letter, now and then

New entries arrive by email when they are ready. No ads, no sponsored posts, no affiliate links.

The button opens your mail app with the message ready to send. Nothing is stored on this site.