Today I would like to write about testing Ruby on Rails applications. Any Ruby on Rails developer that writes tests (are they any who don’t?) with some work experience on large Ruby on Rails projects knows that with each milestone, running a test suite takes longer and longer. A relatively small RoR project, estimated for about 400 hours of Rails developer work has a test suite (Cucumber and Rspec) that takes about 7 minutes to run.

But when the project is larger, has a significant amount Javascript, therefore involving Culerity and Selenium support/integration within your Ruby on Rails application test suite, you begin looking for ways to cut some of that time off.
For example, in Selleo, we have a 3000 hours project, which test suite takes way more than half an hour. Of course, we are using Teamcity, tag scoping, etc but it still takes a lot of our precious development time.

An individual or software development company who/which wants to optimize the time that is being consumed by testing should look for bottlenecks.
Unit tests, the idea of it, is to test some method or functionality in abstraction of other part of Ruby on Rails application, therefore each time a test runs, the needed environment is generated. But since most of Ruby on Rails applications require an instance of User, it is a waste of time to generate user for each single test.

So it’s nice to generate some fixtures and setup a database properly, remembering that the fixtures should be sort of minimalistic, because large fixtures file for Rails application introduce often a bloat – it’s hard to manage such file and you often repeat yourself.
Therefore, a smart programmer should combine fixtures with factories. It’s easy since there are many good gems to play with, like Factory Girl or Machinist, that allow you to quickly mock objects you need, in a particular test, using blueprints.

You get the best of both worlds this way, delivering great and reliable applications for your customers.