O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Fixtures vs. Factories vs. Test Doubles

To sum up, Rails provides fixtures as an exceptionally simple way to create a set of test data that can be shared across multiple tests. However, fixtures are so simple that they tend to not be adaptable to more complex product needs. Factory tools, which take a little bit more initial setup, allow for more flexibility at some cost in test performance. The two structures are not mutually exclusive. One pattern for combining them is to create a complex scenario in fixtures for use in integration or complex controller tests, and to use factories for unit tests or simpler controller tests.

Fixtures and factory tools allow you to get test data into your database to create a known baseline for testing. However, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required