Because AJAX Web applications work asynchronously, testing them is tricky. The image at the bottom of this blog entry illustrates a technique which has proven to be successful in practice. A test scenario run starts by calling a program-defined function asyncCall() which lives in the test harness. Execution of function asynchCall() causes the Application under test to send an asynchronous XMLHTTP request to the Web sever and also calls a program-defined delay() function. The delay function loops while the Web server processes the request and returns the asynchronous response, probing the state of the Web application every so often. After the response is received by the client and the app state is updated, the delay() function finds the Web page state-change, and the test harness can examine the new state of the Web application to determine a pass-fail result. Then, a new asynchronous call can be made, continuing the test scenario. This process repeats until the scenario finishes all its steps, and the final state of the Web app can be examined, and results logged to a file or database. I’ve written this interesting technique up, and it will appear in MSDN Magazine in a few months.