Performance: Fixture and factory usage
This affects test suite execution speed and memory usage during development and CI runs.
FactoryBot.define do
factory :user do
name { "Test User" }
email { "user@example.com" }
end
end
# Create only needed test data on demand with factoriesfixtures :users, :posts
# Tests rely on large YAML fixture files loaded before the suite runs| Pattern | Test Startup Time | Memory Usage | Test Execution Speed | Verdict |
|---|---|---|---|---|
| Large YAML Fixtures | High (loads all fixtures before tests) | High (all fixture data in memory) | Slower (due to memory pressure) | [X] Bad |
| On-demand Factories | Low (creates data per test) | Low (only needed data in memory) | Faster (less memory overhead) | [OK] Good |
user.name output?
FactoryBot.define do
factory :user do
name { "Bob" }
end
end
user = FactoryBot.create(:user)users.yml with a user named john. In your test, you write users(:john) but get an error. What is a likely cause?users(:john) will raise an error.Pass the test and this pattern moves unknown