Structure your tests: describe, hooks, tags

Knowledge Videos

Short animated explainers, organised by subject.

Structure your tests: describe, hooks, tags

Group tests with describe, share setup in beforeEach, keep every test independent in a fresh browser context, and pick what to run with tags like @smoke.

Transcript

A test file groups related tests. Use test dot describe to name a group, like Login. Inside it, each test checks one behavior and has a clear name, so the report reads like a list of test cases.

Put the steps that every test repeats into before each. It runs before every single test, for example to open the login page.

Keep every test independent. A test must never depend on another test running first, or on data it left behind. Each test gets a fresh browser context, like a brand new private window.

Use tags like at smoke to choose what to run. Run only the smoke tests on every commit, and the full suite every night.

Remember: describe groups tests, before each shares setup, every test stands alone, and tags choose what to run.

More in this series