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:

tasks.test {
   filter {
  • add the MicroEJ JavaScript dependency in the build file of the project:
  • define the platform to use to run the tests with one of the options described in Platform Selection section
  • create a file assert.js in the folder src/test/resources with the following content:
var assertionCount = 0;

function assert(value) {
        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 folder src/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.