Running Drupal tests under TeamCity
2012-06-05
The annoying thing about Drupal’s tests is that they seem to be optimized for running them manually which is insane in my opinion. Using some hacks it is possible to run them under TeamCity.
Requirements
- a working TeamCity instance
- a webserver
- a MySQL server
Create a project and build configuration in TeamCity and configure it according to your vcs settings. In the build configuration the following build steps are needed.
TeamCity build steps
-
Install site via drush:
drush -y site-install testing --db-url=mysql://USERNAME:PASSWORD@localhost/DATABASE --clean-url=0 --site-name=SITENAME
-
Enable simpletest module:
drush -y pm-enable simpletest
-
Enable custom modules that you want to test:
drush -y pm-enable MODULENAME
-
Symlink webserver root and set permissions via shell script:
#!/usr/bin/env zsh ln -fs %teamcity.build.checkoutDir% /var/www/servers/localhost/html/MYSITE chmod -R go+w sites/default/files mkdir scripts/tests chmod 775 scripts/tests
-
Run tests:
/usr/bin/php scripts/run-tests.sh --url http://localhost/MYSITE/ --php /usr/bin/php --xml scripts/tests "NAME OF TESTSUITE"
To process the test results you have to add an additional build feature. Choose XML report processing and the Ant JUnit format. The file pattern should be
scripts/tests/*.xml
Warning
Do not run the whole drupal test suite! It will take ages to complete!
You should keep sure that your webserver is only accessible from the build agent.