Skip to content

Using Fixtures in Minitest

Ngan Pham edited this page Feb 24, 2026 · 1 revision

Using Fixtures in Minitest

Setup

# test/test_helper.rb
require "fixture_kit/minitest"

class ActiveSupport::TestCase
  self.use_transactional_tests = true
end

The Minitest entrypoint sets:

  • fixture_path default to test/fixture_kit
  • adapter to FixtureKit::MinitestAdapter

Declare and Use

class ProjectTest < ActiveSupport::TestCase
  fixture "project_management"

  test "loads data" do
    assert fixture.project.present?
  end
end

Lifecycle Timing

For a class that declares fixture:

  1. Declaration is registered when the class body is evaluated.
  2. run_suite generates cache once for that class before test methods execute.
  3. setup mounts cache and assigns repository to @_fixture_kit_repository for each test.

Runner start (FixtureKit.runner.start) is triggered from class-level run_suite before first cache generation and clears cache path unless preserve-cache is enabled.

Class-Level Behavior

  • Declarations are class-level.
  • Subclasses can declare a different fixture and override parent behavior.

Common Gotcha

If a class doesn’t declare fixture and still calls fixture, FixtureKit raises:

No fixture declared for this test class. Use `fixture "name"` in your test class.

Clone this wiki locally