<SyncTester>
An extension of TestCase for testing asynchronous objects safely.

JavaScript: lz.SyncTester
extends <TestCase> » <Test> » <DebugObject> » <view> » <node> » lz.Eventable »

SyncTester is an extension of TestCase that is useful for testing objects whose method are to be called sequentially, in effect synchronizing methods with potentially asynchronous behavior.

To take advantage of this helper class, you must declare a dataset named "<instance name>_methods", with a root node whose children are the method names to be called synchronously. The method nodes must be named "call", and have at least the "name" attribute defined. If the method needs to be called with arguments, specify them as value of the optional "args" attribute (only one argument is currently supported).

Your specific tests will only run once a method returns. It is possible to provide an inspector method for each of the asynchronous methods declared; you reference it with the "tester" attribute of a node in the dataset. These inspector methods must be defined on the SyncTester object. If you dont specify a tester for a method, the default handler named inspect will be called with the result of the method call as an argument. You should override this method if you want to have a generic inspector for most or all of your methods.

Generally speaking, you would expect that an event is sent when a method is done. This framework allows you to specify what event indicates the end of method execution by declaring the "event" attribute. It is assumed that the sender of the event is the object referenced by the tested_object attribute, or that the following method accepts a delegate to call on completion, as the last argument. If neither of these assumptions is correct, the flow of method execution will break.

For example, if you have an instance of this class named "userinfo", then your list of methods might be declared like this:

                    
    <dataset name="userinfo_methods">
        <suite>
            <call name="isAuthenticated" args="admin"/>
            <call name="getExpiration" event="ondata"/>
            <call name="createAccount" event="onload" tester="checkAcct"/>
        </suite>
    </dataset>
                

Attributes

Name (CSS property) Type (tag) Type (js) Default Category
current_method expression any cur_meth.xpathQuery('@name') readonly
  Helps keep track of currently executed method
del expression any   read/write
   
tested_object expression any   read/write
  Refers to object to be tested; this is dependent on specific test run

Attributes inherited from <TestCase>

name, testnames

Attributes inherited from <DebugObject>

debugWrite

Methods

inspect()
SyncTester.inspect(res);
Override this method with your specific test logic
Parameter Name Type Description
res   this is the result of execution of the last called method, typically its return value.

Methods inherited from <TestCase>

addTest, addTests, run, setUp, tearDown

Methods inherited from <formatter>

abbreviate, formatToString, pad

Methods inherited from <DebugObject>

jsTrue, xmlequals, xmlstringequals

Methods inherited from lz.Eventable

destroy, setAttribute

Events

Events inherited from <node>

onconstruct, ondata, oninit

Events inherited from lz.Eventable

ondestroy