Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

SimpleTests for Drupal Modules

Parent Feed: 

I recently completed the process of adding SimpleTest tests to two modules that I maintain on drupal.org: Porter Stemmer (a module that adds linguistics-based matching of word forms to Drupal's core Search module, so that you can match "walk", "walking", "walks" etc. in searches), and Search by Page (a module that lets you search Drupal site pages (nodes, user profiles, attachments, and other pages such as views) as they are rendered by your theme, and allows you to restrict searching to certain content types, user roles, attachment fields, and/or other pages on your site).

It was an interesting experience. SimpleTest is pretty well documented, and I've been a professional software developer for a long time, so the concept of testing is not new to me. But it took quite a while to decide exactly what I should test (functional and unit tests), to figure out the details of SimpleTest (such as how to get cron to run and how to use its built-in browser), and when my first tries at tests inevitably failed, to decide whether the tests or the modules were at fault and fix the bugs.

The end result was worth it though. For one thing, I found several bugs both modules in the course of testing, as the tests are quite thorough. For instance, the Porter Stemmer tests go through a huge list of words provided by Porter (the creator of the stemming algorithm) and verifies that all the words are stemmed correctly to their root forms, and also has a functional test that verifies that the module meshes correctly with Drupal's core Search module. The Search by Page module tests that only the content you want to search is searched, that permissions are honored, and also tests many more options than an ad-hoc "let's see if this is working" sort of test would be able to verify.

Another benefit is "regression testing": whenever I make an update to either module, I can run the tests and be reasonably certain that my changes aren't going to break anything. And since SimpleTest has been incorporated into the core of Drupal version 7, when I port my modules to Drupal 7, I can also port the tests and once I get the tests to pass, I'll be reasonably certain that my modules are working.

All you other module maintainers out there: I recommend that you learn about SimpleTest as soon as possible, if you haven't done so already!

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web