Tests
JavaScript applications can be tested with tests written in JavaScript.
The JavaScript test files must be located in the project folder src/test/js
.
All JavaScript files (*.js
) found in this folder, at any level, are considered as test files.
In order to setup JavaScript tests for your application, follow these steps:
create an Add-On Library project or a Standalone Application project
define the following configuration in the build file of the project:
tasks.test {
filter {
includeTestsMatching("*._JsTest_*Code")
}
}
Add these properties nside the ea:build
tag (if the properties already exist, replace them):
<ea:property name="test.run.includes.pattern" value="**/_JsTest_*Code.class"/>
<ea:property name="target.main.classes" value="${basedir}/target~/test/classes"/>
add the MicroEJ JavaScript dependency in the build file of the project:
implementation("com.microej.library.runtime:js:0.13.0")
<dependency org="com.microej.library.runtime" name="js" rev="0.13.0"/>
define the platform to use to run the tests with one of the options described in Select a VEE Port section
create a file
assert.js
in the foldersrc/test/resources
with the following content:
var assertionCount = 0;
function assert(value) {
assertionCount++;
if (value == 0) {
print("assert " + assertionCount + " - FAILED");
} else {
print("assert " + assertionCount + " - PASSED");
}
}
This method assert
will be available in all tests to do assertions.
create a file
test.js
in the foldersrc/test/js
and write your first test:
var a = 5;
var b = 3;
var sum = a + b;
assert(sum === 8);
build the application in the SDK or in command line with the MMM CLI
The execution of the tests produces a report available in the folder target~/test/html
for the project.