Using a RAM disk to speed up automated tests

A big benefit of automated testing is that it is (much) faster than testing by hand. This makes it possible to use testing as a form of instant feedback. Ideally, the test should be able to tell you something is broken immediately after it breaks. This means the basic test cycle should probably run not much longer as a few minutes. In fact, XP considers this a best practice (the 10 minute build).

When doing a lot of testing with files and databases on a large project, things start to slow down pretty soon. There are several ways to speed things up, like mocking slow dependencies that are not under test or using a fast in-process in-memory database like HSQLDB. HSQLDB is only suitable for very simple database test scenarios. A pragmatic alternative to speed up a real database is using a RAM disk!

A RAM disk emulates a disk drive by storing data in the RAM memory. This means its much faster as an ordinary hard drive, but all data will be lost when the machine shuts down. For an automated test, a RAM disk is a nice fast alternative to test IO and place a temporary test database. For Windows, a free RAM disk driver is available here, there are better commercial drivers available. Most other OS-es have RAM drive functions built-in.

The free driver enables a single drive up to 64mb, which is usually enough for automated testing and probably won't hurt overall system performance. Of course, an automated load- and/or performance test needs more data, but then you wouldn't want to do those kind of tests on a RAM drive anyway. 🙂 When evaluating what to put on the RAM disk, also make sure that the database load scripts/contents are on it too, since this usually is read lots of times during the automated testing.