The Intern Test Framework
The Intern test framework (http://theintern.io/) is the test framework of map.apps and of the dojo framework.
Installation
To integrate the Intern framework in a map.apps maven project two different maven dependencies can be used:
The dependency ct-jsrt-test-intern
contains the default version of Intern which requires a modern browser and has no support for Internet Explorer 8.
<dependency>
<groupId>de.conterra.jsrt</groupId>
<artifactId>ct-jsrt-test-intern</artifactId>
</dependency>
The dependency ct-jsrt-test-intern-geezer
contains a special build of Intern with support for Internet Explorer 8.
<dependency>
<groupId>de.conterra.jsrt</groupId>
<artifactId>ct-jsrt-test-intern-geezer</artifactId>
</dependency>
In the following all URLs where Intern is used has to be replaced by intern-geezer if intern-geezer is used as dependency
|
Check the Installation
Which version of Intern is available can be tested by:
A self test can be started by:
Write a Test
For full documentation about how to write a unit test, see the Intern website . In the following, only a small sample is shown.
The following project structure is assumed:
src/main/js/
+-helloworld // bundle folder
manifest.json // bundle descriptor
hello.js // file to test
\-tests // tests folder to put tests into
hello.js // test for the hello.js file
The contents of the manifest.json
file can look like:
{
"Bundle-SymbolicName": "helloworld",
"Bundle-Version": "1.0.0-SNAPSHOT"
}
The hello.js
can be as simple as:
define([], function () {
return {
sayHello: function (msg) {
if (!msg) {
return "Hello!";
}
return "Hello " + msg + "!";
}
};
});
The test file in tests/hello.js
can look like:
define([
"intern!object", // the Intern object notation is used in this test
"intern/chai!assert", // the chai assertion library is used in this test
"module", // module gives a descriptor of this js file
"../hello" // imports the file to test
], function (registerSuite, assert, md, hello) {
registerSuite({
// the name of the test suite is called like the file, this is a map.apps convention
name: md.id,
// a test is a simple method, it can use a very descriptive name to make clear what is the expected result of the test
// a test should be focused on exactly on requirement
"test that sayHello without a message produces no whitespace between prefix and '!'": function () {
assert.equal(hello.sayHello(), "Hello!", "expected no space between 'Hello' and '!'");
},
"test that sayHello with a message produces whitespace between prefix and the parameter": function () {
assert.equal(hello.sayHello("First Test"), "Hello First Test!");
}
});
});
Run Tests
The base URL to run tests is the runner.html
:
The preceding sample can be started using this URL:
Detailed messages about which tests are executed are available in the browsers JavaScript console. |
Execute Multiple Tests
To execute multiple test at once over multiple packages/bundles a special test package/bundle is required which fetches all tests to execute.
The package is required to get a stable package name for the runner.html.
src/main/js/
+-all-tests // package folder
package.json // package descriptor
all.js // file which lists the tests to execute
The contents of the package.json
can look like:
{
"name": "all-tests"
}
The all.js
has following structure:
define([
"helloworld/tests/hello",
...
"otherpackage/tests/nameoftest"
], 1);
The execution is exactly like described in the run tests section: