AUTOMATEDTESTING IN DRUPAL          Artem Berdishev
What is SimpleTest?• PHP Test Framework• A way to create and run automated regression tests• A functional testing environm...
Why Automated Testing?• Define exactly what the code should do   • Easy development   • Easy to refactor code   • Less deb...
Why Automated Testing?• Once a test is written, it will likely be run many  many times• Every time it is run, it verifies ...
How To Install?•   In Drupal 7, Simpletest is preinstalled.•   In Drupal 6, it must be installed as a contrib module    an...
so… how does it works?• .test files   •   Contain test classes   •   Test classes extend the SimpleTest class         •   ...
Create the class and getInfo()
Create a setUp() for the test class
Create Test Methods
Test Results
API functions•   drupalGet($path, $options = array())•   drupalPost($path, $edit, $submit, array    $options = array(), ar...
Assertions• assertTrue($result, $message = , $group = Other)• assertNull($value, $message = , $group = Other)• assertEqual...
Resources• http://drupal.org/simpletest• http://groups.drupal.org/unit-testing•   The SimpleTest tutorial: drupal.org/simp...
AUTOMATED TESTING    IN DRUPAL        Artem Berdishev        email: berdartem@gmail.com        skype: berdishev
Automated testing in Drupal
Upcoming SlideShare
Loading in …5
×

Automated testing in Drupal

4,148 views

Published on

Automated testing in Drupal
Presentation for first Drupal Cafe in Zaprojie, Ukraine
21 July 2011

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

No Downloads
Views
Total views
4,148
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
41
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Automated testing in Drupal

  1. 1. AUTOMATEDTESTING IN DRUPAL Artem Berdishev
  2. 2. What is SimpleTest?• PHP Test Framework• A way to create and run automated regression tests• A functional testing environment: A pseudo-user navigates in a pseudo-browser and checks the results.• Manipulation (create user, drupalGet(), drupalPost())• Assertions (assertText(), assertPattern(), etc.)• A unit test class is also available, but the general emphasis is on functional testing.
  3. 3. Why Automated Testing?• Define exactly what the code should do • Easy development • Easy to refactor code • Less debugging • Less mistakes• Document Bugs • Prevent regressions • Quality Assurance • Better Software
  4. 4. 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
  5. 5. How To Install?• In Drupal 7, Simpletest is preinstalled.• In Drupal 6, it must be installed as a contrib module and a patch must be applied to core - see the INSTALL.txt.• Enable simpletest module on the modules page (or "drush en simpletest")• Configure "verbose" mode at admin/build/testing/settings (on by default in D7)• Check the status page for problems (admin/reports/status)
  6. 6. so… how does it works?• .test files • Contain test classes • Test classes extend the SimpleTest class • DrupalUnitTestCase • DrupalWebTestCase • Use Helper methods to: • Simulate user actions • Check behavior
  7. 7. Create the class and getInfo()
  8. 8. Create a setUp() for the test class
  9. 9. Create Test Methods
  10. 10. Test Results
  11. 11. API functions• drupalGet($path, $options = array())• drupalPost($path, $edit, $submit, array $options = array(), array $headers = array())• drupalCreateUser($permissions = NULL)• drupalLogin($user = NULL)• drupalLogout()• randomString($number = 8)• randomName($number = 8)
  12. 12. Assertions• assertTrue($result, $message = , $group = Other)• assertNull($value, $message = , $group = Other)• assertEqual($first, $second, $message = , $group = Other)• assertIdentical($first, $second, $message = , $group= Other)• assertPattern($pattern, $message = , $group = Other)• assertText($text, $message = , $group = Other)• assertTitle($title, $message = , $group= Other)• assertLink($label, $index = 0, $message = , $group = Other)• assertResponse($code, $message = )• pass($message = NULL, $group = Other)• fail($message = NULL, $group = Other)• verbose($message)
  13. 13. Resources• http://drupal.org/simpletest• http://groups.drupal.org/unit-testing• The SimpleTest tutorial: drupal.org/simpletest- tutorial-drupal7 (D7) or drupal.org/simpletest- tutorial (D6)• http://drupal.org/project/examples
  14. 14. AUTOMATED TESTING IN DRUPAL Artem Berdishev email: berdartem@gmail.com skype: berdishev

×