October 29, 2005

Speeding up Rails testing

In Faster Testing with Rails 1.0, Mike Clark talks about the changes to testing default in Rails 1.0.
Herewith, an overview of the new testing stuff, a how-to for upgrading your existing tests (though you don't have to), an obligatory math formula or two, and a performance comparison that's worth about as much as you paid to read this.
So I gave it a try...and was more than pleasantly surprised: the total test time was reduced (in one set of runs) from seven minutes down to about 40 seconds: the optimized tests run in just about 10% of the original test time.
Test Suite Run Times for Rails Testing

The following table shows the run times (in seconds) for my Culinary Census test suite. There are maybe 260 to 300 rows of data generated by the fixtures in 15 or so tables. Some 250 rows are static, the rest dynamically generated.

Type of Test No Optimization Non-instantiated Transactional NI
and
Transactional
Unit Tests
96 tests, 474 assertions
370 86 325 35
Functional Tests
47 tests, 170 assertions
60 15 47 6
Total 430 101 372 41

Legend

Use
Transactional
Fixtures
Use
Instantiated
Fixtures
No Optimization false true
Non-instantiated false false
Transactional true true
NI
and Transactional
true false
Posted by ronlusk at October 29, 2005 05:47 PM