Why should I write a simpletest for my module?

Last modified: February 19, 2008 - 03:56

The why

You should write simpletests for your modules to ensure quality. Simpletests allow you, the developer, to quickly test your module after changes to make sure it still works. After all, do you really test all possibilities for error? Of course not; it would be very tedious and time-consuming. So, the logical thing to do is to write a simpletest for it.

Incompatibilities

Say, on your issue queue, you got a report that your module was incompatible with another one. What can you do? You can install that module, run your tests, and see which ones report errors. This will allow you to trace bugs much more efficiently.

Errors

Say that you made an error in your module that causes it to not function properly, but you overlook it. This is BAD. You may even try to make a stable release of it in its broken state, while you're ignorant of the problem. A simpletest will allow you to run automated tests on your module to make sure that, indeed, everything still functions properly.

Others

This is an open source community, and helping others is the core of what Drupal is. What if somebody else is using your module on their site, and they get an error? If you have a simpletest file included, they can run automated tests on you and give you the results, helping you to debug. This way, you get less support requests, because people may find that it's something in their setup that's causing these problems.

What to test?

What should your simpletest test? Well, it can test anything that your module does. Perhaps your module prints a message after a user has viewed a node of type x. Well then, create a simpletest that creates a node of type x, views it, and confirms that the message shows up. Anything that your module does, simpletest should be able to test it to make sure it's working properly: it is up to you to write these tests.

 
 

Drupal is a registered trademark of Dries Buytaert.