Why use Factory Bot instead of creating test data manually?
04-Jun-2020 1281
I recently taught a Rails testing class where we wrote tests using RSpec, Capybara, Factory Bot and Faker.During the class, one of the students asked, why do we use Factory Bot? What’s the advantage over creating test data manually?The answer to this is perhaps most easily explained with an example. I’m going to show an example of a test setup that creates data manually, then a test setup that uses Factory Bot, so you can see the difference.In both examples, the test setup is for a test that needs two Customer records to exist. A Customer object has several attributes and a couple associations.
Why use Factory Bot instead of creating test data manually? #ruby #rubydeveloper #rubyonrails #Factory #instead #creating #manually? #test https://rubyonrails.ba/link/why-use-factory-bot-instead-of-creating-test-data-manually