Drupalcamp Simpletest

1,520 views
1,457 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,520
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
17
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Drupalcamp Simpletest

  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 http://drupal.org/user/33667 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 http://buytaert.net/drupal-7-timeline 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. drupal.org)
  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 http://drupal.org/project/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.” http://groups.drupal.org/node/9408
  14. 14. References Webchick’s presentation “Testing Part 1: Intro to Testing” (Szeged Drupalcon) http://drupal.org/simpletest http://groups.drupal.org/testing-qa One SimpleTest template to rule them all http://groups.drupal.org/node/7731 Drupal testing patterns http://groups.drupal.org/node/15190

×