Running Drupal tests under TeamCity

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

  1. a working TeamCity instance
  2. a webserver
  3. 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

  1. Install site via drush: drush -y site-install testing --db-url=mysql://USERNAME:PASSWORD@localhost/DATABASE --clean-url=0 --site-name=SITENAME
  2. Enable simpletest module: drush -y pm-enable simpletest
  3. Enable custom modules that you want to test: drush -y pm-enable MODULENAME
  4. 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
    
  5. 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.

Jens Grassel Written by:

Solving problems and burning chrome for fun and profit.