Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Testing In Drupal


Published on

Simple Test

Published in: Technology
  • Be the first to comment

Testing In Drupal

  1. 1. Testing in Drupal An Introduction
  2. 2. Who Am I? Simon Roberts IT Consultant, Taniwha Solutions Using PHP since ~1996 Using Drupal since 2005 First used SimpleTest at Drupalcon Szeged Testing Sprint
  3. 3. Who Am I? Before the Drupalcon, I’d only had the most casual of looks at Testing in Drupal Have used JUnit etc previously Was able to provide useful tests to Drupal Core inside a couple of hours!! You can too!
  4. 4. What was SimpleTest? PHP Testing Framework Integrated as a contributed module in D5 + D6 Integrated in core for Drupal 7 (sortof) Implements Automated Testing
  5. 5. Why Automated Testing? Define exactly what the code should do Easier development Easier to refactor code Less debugging Less mistakes More fun!!
  6. 6. Why Automated Testing? Document Bugs $xss = '<script>alert(quot;xssquot;)</script>'; $edit = array( 'title' => $xss, ); $node = $this->drupalCreateNode($edit); $this->drupalGet('node/' . $node->nid . '/edit'); $this->assertNoRaw($xss, t('Harmful tags are escaped.'));
  7. 7. Why Automated Testing? Document Bugs Prevent regressions Quality Assurance Better Software Safety net!
  8. 8. Why Automated Testing? Once a test is written, it will likely be run many many times Every time it is run, it verifies that the code is still working If it catches even one bug, it has “paid for itself” - High value Can be used to help reproduce problems
  9. 9. Testing in Drupal Core Dries (and Drupal!) has made Testing a high priority for Drupal 7 The actual Drupal 6 Timeline Effective Test coverage allows us to compress the “fix” phase of a Drupal release (code freeze) The Drupal 7 timeline assuming that we fully embrace testing. Note: These dates are going to be delayed anyway - slower migration to Drupal 6 than expected (eg: CCK, Views, Panels.
  10. 10. Not just for Drupal Core!
  11. 11. so... how does it work? .test files Contain test classes Test classes extend the SimpleTest class well, not exactly Use Helper methods to: Simulate user actions Check behavior
  12. 12. No, really... how does it work? Let me show you...
  13. 13. What’s Left To Do? Outstanding Testing Issues projects=3060&versions=156281&components=simpletest.module,tests “We currently have 38 tests taken out of 43 for a test coverage of 88%. This will change when the misnamed tests are merged.”
  14. 14. References Webchick’s presentation “Testing Part 1: Intro to Testing” (Szeged Drupalcon) One SimpleTest template to rule them all Drupal testing patterns