Rails Test Suite Launch Speed

I have 357 tests (534 statements) for my application (using the Paste function). The entire test suite runs after about 80 seconds. OK this time? I'm just curious, as this is one of my first applications where I write tests extensively. No fancy stuff in my app.

Btw: I tried to use the sqlite3 database in memory, but the results were surprisingly worse (about 83 seconds). Any clues here?

I am using a Macbook with 2 GB of RAM and a 2 GHz Intel Core Duo processor as my development machine.

+4
source share
7 answers

I do not feel that this question is related to rails, so I will call.

The main thing in testing is that it should be fast enough so that you can run a lot of them (as well as all the time). In addition, you can divide your tests into several different sets, in particular, such as "lengthy tests" and "unit tests".

One of the last options to consider if your database setup is time-consuming is to create your domain by restoring it from a backup, rather than making a whole bunch of inserts.

Good luck

+2
source

You should try this method https://github.com/dchelimsky/rspec/wiki/spork---autospec-==-pure-bdd-joy- , using spork to speed up several processes that continue to work and execute batch tests. I found this pretty quickly.

+2
source

It really depends on what your tests do. Test code can be written efficiently or not exactly the same as any other code.

One obvious optimization in many cases is to write your test code so that everything (or as much as possible) is executed in memory, unlike many read / write operations to the database. However, you may need to change the application code to get the right interfaces.

+1
source

Large test suites may take some time.

I usually use "autospec -f" in development, it only runs specifications that have changed since the last run, which makes it much more efficient for your tests to work.

Of course, if you are really serious, you will run the continuous integration setup, for example Cruise Control - this automates the build process and starts in the background, checking your last building and launching the package.

+1
source

If you want to speed up the execution of your test suite, I would use a test server, for example this one from Roman Le Nรฉgrate.

+1
source

Unlike SQLite in memory, you can put the MySQL database in RAMDISK (on Windows) or on tmpfs on Linux.

MySQL has very efficient buffering, so placing the database in memory does not help much while you frequently refresh a lot of data.

More important is the way to isolate the test and prepare the data for each test.

You can use transactional lights. This means that each test will be wrapped in a transaction, and therefore the next test will start from the starting point.

This is faster than clearing the database before each test.

There are situations when you want to use both transactions and explicit data deletion, here is a good article: http://www.3hv.co.uk/blog/2009/05/08/switching-off-transactions-for-a-single- spec-when-using-rspec /

0
source

You can experiment with preloads, but it will be harder to maintain, and IMHO, itโ€™s not worth the speed to improve (maximum 20%, I think, but it depends)

SQLite is known to be slower than mysql / pgsql, with the exception of very small, tiny DBs .

As already mentioned, you can put mysql (or other DB) data files on some RAMDisk (I use tmpfs for linux).

PS: now we have 1319 examples of Rspec, and it works for 230 seconds on C2D-3Ghz-4GRam, and I think this is normal. So yours is fine too.

0
source

All Articles