How to write test cases for custom ajax functionality using simpletest in drupal7 I am trying to write the test case for my custom ajax functionality in Drupal 7. I am firing the event on click in my .js file but the test case gets a fail.

In my .tpl.php template file I have the following code:

&lt;a href="javasctipt:void(0)" id="myFirstEvent"&gt;Click Here&lt;/a&gt;

In the Js file I am getting the event as follows:

$('#myFirstEvent').live('click', function())
$.ajax({
        cache: false,
        url: Drupal.settings.basePath + '?q=mymodule/add',
        data: {page: page, sort: sort, order: order},
        dataType: 'text',
        error: function(request, status, error) {
            alert(status);
        },
        success: function(data, status, request) {
            /**Function definition goes here**/

}


In my custom.test file I have the following:

$edit = array();
$this&gt;drupalGet("myform/add");
$this-&gt;drupalPost('myform/add', $edit, 'myFirstEvent');
$this-&gt;assertResponse(200, 'Success');


But I am not getting the success screen (Green Color) after I execute my test cases.
You cannot test custom javascript with simpletest because it simply ignores them. Simpletest can simulate the ajax behavior (via xpath) only if you add that to the form with the #ajax property. http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#ajax 

To test custom js you might want to have a look at Selenium.