vendredi 11 décembre 2020

Baseline global seed data with FactoryBot

TLDR: What is the best approach to seed global data with FactoryBot?

Currently, we have a fairly large application and using FactoryBot for most tests. However, we are still using fixtures to seed some default data in a database, for CRUD tests that need to talk to the DB, and can't be "stubbed".

Using fixtures to seed data, lets us shave off 50% of the time during setup/teardown for things that are common for almost all CRUD tests.

Also for some business rules validations, we need to use actual data, not 'faked' from Faker.

Examples of the seed model/fixtures:

  • ShippingMethod (FedEx, UPS, USPS, etc. )
  • User (user record is used in almost every other model)
  • Warehouse (we only have 2)
  • Setting ( some global app settings)

Actual Question

What is the best practice to use inside FactoryBot to move away from using fixtures completely, so that we maintain test data in one spot, or this a good use-case for fixtures to be used with factories?

Keep in mind that since tests are run in parallel, seed data needs to be available to all tests throughout the run of the test suite.

Thank you for any suggestions.

Aucun commentaire:

Enregistrer un commentaire