Starbow Consulting

Starbow Consulting

Home Tao's Blog Contact Search

Home

Tao's Blog

Contact

Search

Home » Blogs » tao's blog Joys of Unit Testing Submitted by tao on Thu, 2007-03-29 11:32 Drupal testing Back when I was a java programming I fell in love with test-first development, where you write you tests a little in advance of coding in a feature (or at least in concurrence with). I could babble on about all the benefits the approach brings, but the key to using it is that it has to be quick and easy. Unfortunately, with Drupal it is neither. But testing is possible, and still useful, since I the fragment work I am doing is kinda hairy and needs to be air-tight. There are two major branches of automated testing; unit or white box vs functional or black box testing. Functional testing a Drupal site means going through the browser and interacting with it as if you were a user. The best tool I have found for this is Selenium, and one of the cool things about this type of testing is that that anyone, of any level of experience can help out. Unit testing is focused and developer driven. Each feature of your code should have a couple of unit tests that exercises it in isolation of the rest of the system. Here is where you test different failure states and edge cases. Every time you discover a bug, you should create a unit test that reliably triggers it, then fix the bug and verify that the test now passes. This is your best defense against regression. The cliche is that if a feature does not have a test, it doesn't exist. Of course, by that standard Drupal doesn't exist at all. As far as I know, the best tool for unit testing Drupal is the SimpleTest module (http://drupal.org/project/simpletest) that Moshe built around Last Craft's Simple Test Framework (http://www.lastcraft.com/simple_test.php) I can't think of a single open source Java project that does not come with JUnit, and Rails has testing baked in, but SimpleTest seems to be something of a red-heading step-child in the Drupal word. Moshe did a good chunk of work getting Drupal and Simple Test to work together, and spent a while pushing it, but it never seemed to gain traction. There isn't even an offical 5x version, although HEAD does work. Sorry for the ranting. I actually meant to blog about some cool SimpleTest/Drupal tips, but I will break those into another post. tao's blog Add new comment

Joys of Unit Testing Submitted by tao on Thu, 2007-03-29 11:32 Drupal testing Back when I was a java programming I fell in love with test-first development, where you write you tests a little in advance of coding in a feature (or at least in concurrence with). I could babble on about all the benefits the approach brings, but the key to using it is that it has to be quick and easy. Unfortunately, with Drupal it is neither. But testing is possible, and still useful, since I the fragment work I am doing is kinda hairy and needs to be air-tight. There are two major branches of automated testing; unit or white box vs functional or black box testing. Functional testing a Drupal site means going through the browser and interacting with it as if you were a user. The best tool I have found for this is Selenium, and one of the cool things about this type of testing is that that anyone, of any level of experience can help out. Unit testing is focused and developer driven. Each feature of your code should have a couple of unit tests that exercises it in isolation of the rest of the system. Here is where you test different failure states and edge cases. Every time you discover a bug, you should create a unit test that reliably triggers it, then fix the bug and verify that the test now passes. This is your best defense against regression. The cliche is that if a feature does not have a test, it doesn't exist. Of course, by that standard Drupal doesn't exist at all. As far as I know, the best tool for unit testing Drupal is the SimpleTest module (http://drupal.org/project/simpletest) that Moshe built around Last Craft's Simple Test Framework (http://www.lastcraft.com/simple_test.php) I can't think of a single open source Java project that does not come with JUnit, and Rails has testing baked in, but SimpleTest seems to be something of a red-heading step-child in the Drupal word. Moshe did a good chunk of work getting Drupal and Simple Test to work together, and spent a while pushing it, but it never seemed to gain traction. There isn't even an offical 5x version, although HEAD does work. Sorry for the ranting. I actually meant to blog about some cool SimpleTest/Drupal tips, but I will break those into another post. tao's blog Add new comment

Joys of Unit Testing Submitted by tao on Thu, 2007-03-29 11:32 Drupal testing

Drupal

testing

Back when I was a java programming I fell in love with test-first development, where you write you tests a little in advance of coding in a feature (or at least in concurrence with). I could babble on about all the benefits the approach brings, but the key to using it is that it has to be quick and easy. Unfortunately, with Drupal it is neither. But testing is possible, and still useful, since I the fragment work I am doing is kinda hairy and needs to be air-tight.

There are two major branches of automated testing; unit or white box vs functional or black box testing.

Functional testing a Drupal site means going through the browser and interacting with it as if you were a user. The best tool I have found for this is Selenium, and one of the cool things about this type of testing is that that anyone, of any level of experience can help out.

Unit testing is focused and developer driven. Each feature of your code should have a couple of unit tests that exercises it in isolation of the rest of the system. Here is where you test different failure states and edge cases. Every time you discover a bug, you should create a unit test that reliably triggers it, then fix the bug and verify that the test now passes. This is your best defense against regression. The cliche is that if a feature does not have a test, it doesn't exist. Of course, by that standard Drupal doesn't exist at all. As far as I know, the best tool for unit testing Drupal is the SimpleTest module (http://drupal.org/project/simpletest) that Moshe built around Last Craft's Simple Test Framework (http://www.lastcraft.com/simple_test.php)

I can't think of a single open source Java project that does not come with JUnit, and Rails has testing baked in, but SimpleTest seems to be something of a red-heading step-child in the Drupal word. Moshe did a good chunk of work getting Drupal and Simple Test to work together, and spent a while pushing it, but it never seemed to gain traction. There isn't even an offical 5x version, although HEAD does work.

Sorry for the ranting. I actually meant to blog about some cool SimpleTest/Drupal tips, but I will break those into another post.

Add new comment

Recent Drupal Posts Working at GoingOn Networks BADCamp 2010 Notes from BADCamp Eclipse Installfest Welcome to BADCamp 2009 Example from Intro to Module Development Presentation Quick WYSIWYG with Image uploading recipe more Recent comments Hi Tao! Can you post 1 year 25 weeks ago Mayk Brito on: Working at GoingOn Networks No way 1 year 25 weeks ago tao on: Mysqldump and Unicode This only works for the first item in a node reference results.. 1 year 29 weeks ago Anonymous on: Reverse Node References On drupal.org? 1 year 29 weeks ago Simon on: Wikis in Drupal 6 - Module R... $form_state in Drupal 6 1 year 33 weeks ago vagkavan on: The best way to show results... more Tweets by @tstarbow Something is up. I passed two smoldering telephone poles in Berkeley after work today. One is weird, two is suspicious. 1 week 2 hours ago Milo was not into dancing this morning. Ah well. Off to pinkalicous. 11 weeks 3 days ago #BADcamp opening my mind to the wonders of Drush 5...which is tricky as @stephthegeek mixes a serious cocktail. 28 weeks 4 days ago Ha #BADcamp finally capped registration at 1500! Could be a little crowded tomorrow :) 28 weeks 5 days ago 1 of 55 ›› Follow me on Twitter Today's popular content Setting up Eclipse PDT and XDebug (26) Wikis in Drupal 6 - Module Review (19) The best way to show results? (11) Drupal and Spam 2.0 Presentation (11) Ahah Session Slides (10) more User login Username: * Password: * Request new password

Working at GoingOn Networks

BADCamp 2010

Notes from BADCamp Eclipse Installfest

Welcome to BADCamp 2009

Example from Intro to Module Development Presentation

Quick WYSIWYG with Image uploading recipe

Hi Tao! Can you post 1 year 25 weeks ago Mayk Brito on: Working at GoingOn Networks

No way 1 year 25 weeks ago tao on: Mysqldump and Unicode

This only works for the first item in a node reference results.. 1 year 29 weeks ago Anonymous on: Reverse Node References

On drupal.org? 1 year 29 weeks ago Simon on: Wikis in Drupal 6 - Module R...

$form_state in Drupal 6 1 year 33 weeks ago vagkavan on: The best way to show results...

Something is up. I passed two smoldering telephone poles in Berkeley after work today. One is weird, two is suspicious. 1 week 2 hours ago

Milo was not into dancing this morning. Ah well. Off to pinkalicous. 11 weeks 3 days ago

#BADcamp opening my mind to the wonders of Drush 5...which is tricky as @stephthegeek mixes a serious cocktail. 28 weeks 4 days ago

Ha #BADcamp finally capped registration at 1500! Could be a little crowded tomorrow :) 28 weeks 5 days ago

1 of 55

Setting up Eclipse PDT and XDebug (26)

Wikis in Drupal 6 - Module Review (19)

The best way to show results? (11)

Drupal and Spam 2.0 Presentation (11)

Ahah Session Slides (10)

Request new password