Skip to main content
InterviewHubPRO
Section Overview
Q12

Question 12 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

24%
Software Testing & QA (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What are Test Fixtures and Factories (Fishery / FactoryBot)?

junior LevelCode Examplesoftware-testingBasic

In Simple Words:

  • Static Fixture Files (user.json): Hardcoded JSON files. Anti-pattern because tests become coupled to shared static mock data; editing a user fixture for Test A breaks unrelated Test B.
  • Dynamic Factories (fishery): Functions that instantiate valid mock objects with sensible defaults, allowing individual tests to override only the specific properties they care about:
    typescript
    import { Factory } from 'fishery';
    
    export const userFactory = Factory.define<User>(() => ({
      id: faker.string.uuid(),
      email: faker.internet.email(),
      role: 'customer',
      isActive: true
    }));
    
    // In test: override only role
    const admin = userFactory.build({ role: 'admin' });