Excellent test-cases for Simpletest Drupal 7 Framework

Simpletest/Testing module allows the Drupal Developers to write test cases along module development Let us write a simple drupal module in Drupal 7 with testcase. Our Drupal module will simply create a Helloworld Block.
Our custom module will be called as simpletestdemo. As from Drupal 7 the custom modules should reside in sites/default/modules directory. We will create our new module directory simpletestdemo in sites/default/modules.

Our Custom module will Simply Create a Block and display the custom message.

Step 1: We will create our simpletestdemo.info file first. Here we need to mention the modulename,description,version. In order to write test cases for our module we need to specify a file called simpletestdemo.test in our info file.

Step 2: Nextstep we ll create our simpletestdemo.module file

Step 3: And now we are going to write the simpletestdemo.test file. we are creating our Testcaseclass here which extends the Drupalwebtestcase. The Drupalwebtestcase is the Baseclass for running drupaltests. The setup function passes the module name to the Baseclass. The getinfo function accepts 3 arguments i)name- Testcase name that shows in the admin ii) description- A small description for the testcase iii) group- group to which the test case belongs .

Step 4: Our simpletestdemoTestcase class will test the block contents using testBlockview function which in turn calls assertTrue which compares whether the title of the block with the given argument. To run the test case navigate to admin/config/development/testing and select simpletestdemo test case and click run test

Step 5: And finally our test case results will be displayed as shown below