Speed up SilverStripe Unit Testing with SQLite

Unit testing can be a useful process to kill those pesky bugs, luckily with SilverStripe its relatively easy to get started unit testing. Running a test can take some time though, a great way of speeding up unit testing (as pointed out to me by Will Rossiter on the IRC channel) is to use the SQLite3 module by Andreas Piening. [ad#Half Banner] Installation is pretty straight forward, so that only your unit tests use the SQLite database you can hack up the config file a bit:

if (strpos($_SERVER['REQUEST_URI'], '/dev/tests') !== false) {

$databaseConfig = array(
"type" => 'SQLiteDatabase',
"server" => '',
"username" => '',
"password" => '',
"database" => 'somename',
"path" => '/var/www/htdocs/path/to/project/assets/.db',

Any request that includes /dev/tests will now use the SQLite database driver. Its generally recommended that you use the same DB driver for your unit testing as you do for your application, so if you use SQLite for testing but MySQL for the actual application it could be worthwhile to run a few tests using MySQL instead. The assets folder is a useful location for the database files because it already has the necessary file permissions set. An .htaccess file will be generated in the .db folder which will "deny from all" so that the actual db file is not publicly accessible.