...
...
Code Block | ||
---|---|---|
| ||
function setUp() { //Code here to setup the environment for the testcases in this scope } function tearDown() { //Code here to cleanup the environment after running the testcases in this scope } |
When testing asynchronous code, for example a queued method using the queueMethod method of the Headless Client plugin with a notifyCallback method or a executeAsyncRequest on the HTTP plugin with a success/errorCallback and the UnitTest needs to test the result of the callback method, application.updateUI(Number:milliseconds) can be used inside a loop to wait for the callback to be invoked and test it's result.
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* @type {Number}
*/
var TIME_OUT = 1000
/**
* @type {Number}
*/
var UPDATE_WAIT = 100
var callbackReceived = false
/**
* @type {Object}
*/
var callbackRetval
function testLocalLinkCallback() {
callbackReceived = false
//Your code here that invoked something that used testCallback as callback method
var it = 0
while (!callbackReceived && it < TIME_OUT / UPDATE_WAIT) {
application.updateUI(UPDATE_WAIT);
it++
}
if (!callbackReceived) {
jsunit.fail('callback not invoked within TIME_OUT period')
} else {
//Check the content of callbackRetval here using jsunit.assert*
}
}
function testCallback() {
callbackReceived = true
callbackRetval = //Store whatever you need to complete your test in calbackRetval |
...