If you are familiar with the SimpleTest module then you may already be aware of Drupal's testing Framework. In Drupal 7 the testing framework can now be found in core.
If you are familiar with the SimpleTest module then you may already be aware of Drupal's testing Framework. In Drupal 7 the testing framework can now be found in core. The purpose of this framework is to test the logic of custom modules or any add-on modules. We will do a quick walkthrough of the framework and look at some of the hooks that your custom module may want to implement to interact with the testing framework. For a complete discussion of building tests using the testing framework, see the simple test documentation.
Testing Checklist
Make sure:
- The CURL extension for PHP is enabled.
- A memory_limit of at least 256 MB should be configured.
- “Testing” module is enabled.
After you have completed this initial configuration, you are ready to run tests. You can run tests by navigating to the test manager found in Administartion >> Configuration >> Development >> Testing or by navigating directly to admin/config/development/testing.
Running tests
The interface for testing will look as followed: [image – testing 1] The way this works is to select the test you would like to perform and click Run tests at the bottom of the page. This page will list Drupal core and all active modules that are available for testing. After the tests are run, a report will be presented to you describing the results of the test. [image – testing 2]
Creating Tests
To create a test for your module, you would need to create a PHP file that uses the naming convention, modulename.test where modulename is the name of your custom module. Within this file, you will create a class that inherits from DrupalWebTestCase. The DrupalWebTestCase features an internal browser that can be used to navigate throughout your test site.
The class created will allow you to create tests and set up your test case prior to running the tests, and clean up after the tests completed. If you would like to interact with the testing framework the use of hook_test_finished, hook_test_group_started, hook_test_group_finished can be utilized. The first hook, being the hook_test_finished is a hook that is called when a test has finished.
The code will look like:
hook_test_finished($results)
The hook_test_group_started is a hook that is called when testing a specific test group has started. This hook can be utilized as: hook_test_group_finished()
. The hook_test_group_finished is a hook called when testing of a specific test group has completed. This hook can be called by using hook_test_group_finished ()
This just a small guide as to the capabilities of the testing framework now found in Drupal 7 core. To get a further understanding of the testing framework and how to get started you can read Getting Started with SimpleTest.
No comments:
Post a Comment