Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • A JSUnit node to the Solution Explorer, exposing the assert functions used in testcases
  • An entry in the content menu of the Active Solution to run the Unit Tests
  • A J(S)Unit JSUnit view for viewing the results of a testrun

...

Code Block
titleExample
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
}

 

Testing Asynchronous Code

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
languagejs
titleAsynchronous UnitTest template
/**
 * @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

 

assertEquals vs. assertSame

...