What is a test fixture?

Answer

A test fixture is the fixed state of the environment required for a test to execute consistently — setting up the preconditions for the test. It includes: test data (specific records in the database, JSON payloads), initialized objects (services, repositories), configured mocks, and cleaned-up state after the test. Fixture setup/teardown methods: xUnit (C#): constructor (setup) / IDisposable.Dispose() (teardown). NUnit: [SetUp] / [TearDown] per test; [OneTimeSetUp] / [OneTimeTearDown] once per class. JUnit (Java): @BeforeEach / @AfterEach. Jest: beforeEach / afterEach, beforeAll / afterAll. Fixtures should be: minimal (only what the test needs), fast to set up, and isolated (one test's fixture doesn't affect another). Database fixtures: use transactions rolled back after each test, or test containers with fresh state.