I’m helping a team create their first automated tests
I’m helping a team create their first automated tests.
Here are 8 common testing mistakes I’m seeing, and how to fix them:
1. Unclear name.
Solution: The name should describe the scenario under test and what we expect to happen in that scenario. Format: “should x when y”.
2. Too slow.
Solution: Often the app itself is slow, so fix that! Or consider mocking. Unify in-browser tests to minimize the number of times the app is loaded from scratch. Parallelize tests on CI.
3. Relies on unstable database data.
Solution: Mock via @ApiMocking.
4. Tests for implementation details like HTML id, class.
Solution: Use @TestingLib and @playwrightweb built in locators instead.
5. Doesn’t test what the name claims.
Solution: Code review. Make sure the test name matches what the test is doing. And make sure it fully tests the feature.
6. Non-atomic (fails if run out of order, alone, or with other tests).
Solution: Avoid shared state. Create the data you need to test with via the UI. For example, create a record, then delete it. Or create a dedicated test DB with static scripts to quickly populate the tables. Reset the DB between test runs if you must.
7. Uses the wrong tool.
Solution: I suggest Jest/Vitest for unit testing, and Cypress or Playwright for integration and e2e testing (to automate the browser).
8. Misclassified.
Solution: Store unit, integration, and e2e tests separately so they’re easy to run separately. These tests tend to use different patterns and tools. So the separation helps people understand how to implement each type of test properly because it’s easy to find nearby code to copy.