31
  • What are the tools used for TDD in Drupal?
  • What does your commit/test/deploy workflow look like? Do you use Phing, PHPUnderControl, Hudson for managing this workflow?
  • In which way does unit testing make your code more reliable?
  • Do you need a separate, expensive, stand-alone unit test server, or can you do it from a laptop?

I know that Robert wrote an excellent technical post on An Introduction to Unit Testing in Drupal; I am more interested in covering the workflow and configuration part. Currently I have a development machine, staging and production server. Both production and stage sites run on a 300MB RAM/300MHz CPU Dreamhost VPS.

1
  • This entire thread is now completely outdated. Drupal has a fully integrated testing suite, AND a publicly available testing infrastructure to run tests for community contrib code. A good starting point for reading is drupal.org/docs/develop/automated-testing
    – Hudri
    Commented Mar 31, 2023 at 6:53

3 Answers 3

9

In the ruby world, TDD is facilitated by tools built into the framework. Factory Girl, Mocha, rSpec and others allow developers to create easily and dynamically tests that address the test cases needed.

I've been frustrated as well by the lack to TDD tools in Drupal. My biggest issue with them is the amount of time it takes to run a single test. Development cycles can't be slowed down by individual tests taking 60-90 seconds each iteration. Full test suites would run into the multiple hour timeframe, if you bother to write the tests at all.

I suspect it has to do with copying a full db everytime a test is run, but that's not likely to change in the near future from what I can tell, especially if you need to use DrupalWebTestCase to do so.

I'm hacking together a solution using Phactory and phpunit, which bootstraps Drupal manually. Obviously running into some issues and haven't finished it, but it's getting there.

Fortunately most of my work is at the backend layer, so I can stay at the DRUPAL_BOOTSTRAP_DATABASE level. But I'm running in to more situations where I'll need the full stack.

In the end, TDD in Drupal is not well supported, so you can write your own to make it work outside of the drupal test framework, or endure the poor performance.

-- UPDATE --

I have successfully setup a full Drupal integration with Phactory, and am now running my tests via phpunit instead of the Drupal Web Test Case. So it's possible.

I'll hopefully get to a point where I can release it and it can get incorporated into the Phactory doc.

-- UPDATE 2 --

Doc on how I setup Phactory is at https://github.com/trimbletodd/phactory.

3
  • Thank you for your contribution. It's very interesting what's going on with Phactory for unit testing. Looking forward to see that Drupal module you've been cooking ;) Commented Jul 22, 2013 at 23:22
  • I put up a quick doc of how I am handling Phactory within Drupal on my fork. I submitted a pull request to the master, but it hasn't been incorporated yet. github.com/trimbletodd/phactory Commented Oct 2, 2013 at 21:19
  • This question and it's answers still keep coming back to this day. You rock for rolling your own fork/solution. Therefore, you receive the accepted answer award, Sir. Commented Dec 11, 2013 at 1:53
13

Since Mark's blog is offline, I'll mention some of the tools his team has implemented:

Functional testing: Selenium
Unit testing: Simpletest
Build server: Jenkins
Performance benchmarking: XDebug + Cachegrind

In the two years since I asked this question I've seen some additional tools gain popularity to the TDD scene. Nowadays when you speak of Test Driven Development (in a Drupal context, of course) there's two sides to the same coin — front-end testing, and back-end testing.

Here are two presentations that stand out from the latest Drupalcon Portland 2013 representing this matter:

Development, By The Numbers, backend testing.
Automated testing with Jasmine and PhantomJS, frontend testing.

The first presentation is not related to unit or functional testing (strictly speaking), it's more about tools to measure code quality. Nevertheless, I feel it's somewhat related to the topic.

1
  • 2
    Wow! Thanks for coming back 2 YEARS later to let us know what you discovered! You rock :)
    – Chapabu
    Commented Jun 11, 2013 at 19:33
5

The only thing that I'm aware of is that for contributed modules, you can enable automated testing of commits and patches in the issue queue, see http://drupal.org/node/689990. It is still somewhat unstable, especially if you have dependencies.

Most projects are probably more doing something along the lines of bug driven development, which basically comes down to writing a test first when a bug was found and then fix it. If at all ;)

From my personal experience, TDD is rather hard in Drupal, because you often don't write (only) unit tests with Simpletest but integration tests, where you view pages and submit forms. So it can be rather hard to write good tests in advance. But maybe I'm just not used to doing that :)

Not the answer you're looking for? Browse other questions tagged or ask your own question.