Your SlideShare is downloading. ×
Automated testing in Drupal
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Automated testing in Drupal

3,505
views

Published on

Automated testing in Drupal …

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
3,505
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
33
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. AUTOMATEDTESTING IN DRUPAL Artem Berdishev
  • 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. 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. 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. 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. 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. Create the class and getInfo()
  • 8. Create a setUp() for the test class
  • 9. Create Test Methods
  • 10. Test Results
  • 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. 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. 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. AUTOMATED TESTING IN DRUPAL Artem Berdishev email: berdartem@gmail.com skype: berdishev