Top Banner
AUTOMATED TESTING IN DRUPAL Artem Berdishev
15

Automated testing in Drupal

May 19, 2015

Download

Technology

Artem Berdishev

Automated testing in Drupal
Presentation for first Drupal Cafe in Zaprojie, Ukraine
21 July 2011
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automated testing in Drupal

AUTOMATED TESTING IN DRUPAL

Artem Berdishev

Page 2: Automated testing in Drupal

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.

Page 3: Automated testing in Drupal

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

Page 4: Automated testing in Drupal

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

Page 5: Automated testing in Drupal

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)

Page 6: Automated testing in Drupal

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

Page 7: Automated testing in Drupal
Page 8: Automated testing in Drupal

Create the class and getInfo()

Page 9: Automated testing in Drupal

Create a setUp() for the test class

Page 10: Automated testing in Drupal

Create Test Methods

Page 11: Automated testing in Drupal

Test Results

Page 12: Automated testing in Drupal

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)

Page 13: Automated testing in Drupal

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)

Page 15: Automated testing in Drupal

AUTOMATED TESTING IN DRUPAL

Artem Berdishev email: [email protected]

skype: berdishev