Test fixtures are the fixed setup (data, objects, state) that tests need to run, and setup/teardown methods prepare and clean up this context before and after tests. They reduce duplication and ensure tests run in a consistent, isolated state.
Setup and teardown
SETUP → runs BEFORE tests to prepare the context (create objects, data, connections)
TEARDOWN → runs AFTER tests to CLEAN UP (close connections, delete data, reset state)
→ frameworks provide hooks:
beforeEach / afterEach → before/after EACH test (fresh state per test — common)
beforeAll / afterAll → once before/after ALL tests in a group (shared expensive setup)
(, {
service, db;
( {
db = ();
service = (db);
});
( db.());
(, { });
});
