The innovaphone.test.js lib provides a simple framework for Javascript Unit tests. Scripts can be defined to execute "exe" and "chk" commands. With the "exe" commands mockup objects are addressed to perform simulated functions. With the "chk" commands it is verified that the correct functions of the mockup objects are called.
The scripts are defined as Javascript files, which push objects containing the tests into a global testScrips array.
The user has to provide a test.htm file, which includes all the necessary script and css files and a run.htm, which defines the tests to be executed for automatic tests.
The innovaphone.test.js lib defines an object innovaphone.test for all functions related to the Javascript unit test environment.
This is an object, which should be used as prototype for each object, which needs to be addressed by the test scripts. Typically mockup objects for interfaces use this. The Function init(id) of this object is used to push the object into the innovaphone.test.objs array, in which it can be found by the id.
Internal function, which is used to start the execution of a test script. Typicall the innovaphone.test Console uses this function.
Internal function to execute the next test step. If the test step addresses a mockup object as "obj", this mockup object is found in innovaphone.test.objs and the function exe of this object is called.
Function, which can be called by a mockup object to verify if the detected operation is expected according to the test script. It returns the args object defined in the test script so that the mockup object can verify all parameters.
Internal function to reset everything for the next test. innerHTML of document.body is set to null.
Constructor function to create a myApps Start object as mockup. This is needed to Test a complete App
Constructor function which allocales the test console. The console is displayed as a movable div on top of the module to be tested. It provides the following functions
The function innovaphone.ui1.nodePrototype.testId is set to not only set the id of the object as in the original function, but also to allocate an innovaphone.test.Obj object, so that this object can be addressed from the test script.
This object provides the following functions:
Mockup for the real innovaphone.appwebsocket.Connection object. The script file innovaphone.appwebsocket.Connection.js which contains the "real" AppWebsocket lib should not be used.
Scripts can be loaded as Javascript files. For the manual tests, the console allows to load these scripts from the local file system. The files are executed with the eval function.
The javascript files for test scripts should contain instances as follows for each script (the first line is only needed once).
var testScripts = testScripts || [];
testScripts.push({
title: TITLE;,
file: FILE,
delay: DEFAULT-DELAY,
run: [
[SCRIPTS],
],
steps: [
{ cmd: CMD;, obj: OBJ, op: OP, args: { ARGS }, delay: DELAY},
...
]
});
An html file is needed to load the module to be tested and the innovaphone.test lib. It is recommended to use the name test.htm for this file. The body onload event handler should be used to load a main Javascript object
A test.htm would look like this:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>NAME</title>
<link rel="stylesheet" type="text/css" href="..." />
<script type="text/javascript" src="..."></script>
...
<script type="text/javascript" src="test.js"></script>
<style>
ul,ol {}
div::-webkit-scrollbar {
width: 9px;
height: 9px;
}
div::-webkit-scrollbar-thumb {
background-color: green;
}
</style>
</head>
<body onload="new NAME()">
</body>
</html>
A javascript file is needed for the module specific mockups and as main object to load the module to be tested
function NAME() {
this.exe = function (op, args) {
if (op == "init") {
/* load module to be tested */
...
document.body.appendChild(...);
}
else if(... more operations ...) {
}
...
}
var con = new innovaphone.test.Console(this, "NAME", innovaphone.test);
}
NAME.prototype = innovaphone.test.obj;
A html file is used to define the tests to be executed automatically. It is recommended to use the name run.htm for this file. It should include all the files for the test scripts and uses postMessage to send the test to an iframe, in which test.htm is loaded
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="width:100%; height:100%">
<head>
<meta charset="utf-8" />
<title>Run</title>
<script type="text/javascript" src="... script ..."></script>
...
<script type="text/javascript">
function test() {
document.getElementById("test").contentWindow.postMessage(JSON.stringify(testScripts), "*");
}
</script>
</head>
<body onload="test()" style="width:100%; height:100%; margin:0px; padding:0px">
<iframe title="test" id="test" style="width:100%; height:calc(100% - 5px); border:0px" src="test.htm"></iframe>
</body>
</html>