Test Driven Development
You have been introduced to testing after writing your module because this book is designed for users new to Drupal and/or new to development. Many developers have shifted to writing their tests before writing their code to ensure that the code is written correctly and to reduce bugs during development. This is known as test-driven development (TDD).
Before you write your first test take some time to explore Drupal's testing environment.
Using SimpleTest
Follow these steps to test your website using SimpleTest:
1. Log into your website as the administrator.
2. Enable the Testing module at Modules.
3. Navigate to newly enabled testing area at Configuration O Development O Testing, shown in Figure 17-6.
4. Open the aggregator section and select several of the tests as shown in Figure 17-7.
TRY IT OUT
5. Click the Run tests button at the bottom of the page.
FIGURE 17-6
TESTS
Select the testis) or test group(s) yoj would like to run, and click Run tests.
TESTS
Select the testis) or test group(s) yoj would like to run, and click Run tests.
|
□ |
TEST |
DESCRIPTION |
|
□ |
► Actions | |
|
* Aggregator | ||
|
tí |
Add feed functionality |
Add feed test. |
|
g |
Categorize feed item functionality |
Test feed item categorization. |
|
a |
Import feeds from OPML functionality |
Tes! OPML import, |
FIGURE 17-6
FIGURE 17-7
As the tests are running you'll be presented with a status report as shown in Figure 17-8.
- FIGURE 17-8
After the tests complete you'll be provided with a report (shown in Figure 17-9) outlining which tests passed, failed, or had exceptions. This will allow you to pinpoint potential problems on your site.
RESULTS
437 passes, 0 fails, and 0 exceptions
■.ADD FEED FUNCTIONALITY
Add feed test.
2S passes, 0 fails, and 0 exceptions
■.ADD FEED FUNCTIONALITY
Add feed test.
2S passes, 0 fails, and 0 exceptions
|
MESSAGE |
GROUP |
FILENAME |
LINE |
FUNCTION |
STATUS |
|
Created role of name: s53039458dkDKPy, id: 4 |
Role |
aggregator.test |
12 |
AggregatorTestCase ->setUpO |
y |
|
Created permissions: administer news feeds, access news feeds, create article content |
Role |
aggregator.test |
12 |
AggregatorTestCase->seiUp() |
y |
|
User created with name sS303948TdQxSo7 and pass sd9sXqSPeL |
User login |
aggregator.test |
12 |
AggregatorTestCase->seiUpO |
SimpleTest works by running tests provided with each module. You'll notice that your module was not included in the list because it does not currently have any tests. Tests are written to ensure that the various pieces of a module are working correctly. Drupal's core ships with thousands of tests, the results of which can help you to pinpoint current or potential problems. |
Post a comment