Unfortunately, it also means that developers are dependent on the unit testing framework they decide to use when they start a new project. Moreover, most of the popular JavaScript unit testing frameworks have not been designed to fit the OOP philosophy, like JUnit does.

Consequently, developers face several issues when using the existing frameworks. Currently, unit testing processes are

JUTA implementations are built on top of existing unit testing frameworks, such as Mocha and Jasmine.

Relation to Java

The aim of JEC is to introduce concepts from the Java community into the JavaScript ecosystem. By doing this, we want to take benefits of the highly industrialized processes available in Java environments. That is why JUTA inherits two major features from Java:

a JUnit-like structure

the JEE's APIs and annotations philosophy

Uniforming Unit Testing

One of the most important features of JUTA is that it is exclusively devoted to unit testing projects written with TypeScript. Thus, you can use JUTA to test your Angular apps and your Node.js back end in the same way. This will be really helpful when the GlassCat application server (the default JEC implementation) will be released in a couple of months.

Uniformization of unit testing written in TypeScript provides a real gain regarding test quality and maintainability.

Getting Started With JUTA

The easiest way to start with JUTA is to download the sample project, written with the Tiger framework.

Tiger is the default implementation of the JUTA specification. It is built over the Mocha.js, which is the unit testing framework of the JEC APIs. Note that Tiger is the unit testing framework of all JEC default implementations.

Go to this link and follow the instructions for installing the project. We assume that you are familiar with TypeScript projects and the Node.js development environment.

The project structure is quite easy to address:

The src folder contains the source code of a basic calculator.

The test folder contains all of the test suites related to each class in the src folder.

We recommend you to use the Standard Directory Layout as specified by the Apache Software Foundation to keep tests separate from source files.

Tiger From Scratch

At the moment, Tiger is the first JUTA implementation available for production purposes. Once you have written unit tests for your Angular or Node.js app, you can install Tiger to run them:

$ npm install jec-tiger –save-dev
$ npm install mocha --save-dev

Then, you have to add a basic configuration file (e.g. test-config.ts) to your project to bootstrap the lookup process for test classes:

Finally, set up the command line of your package.json file as follows:

"scripts": {
"test": "mocha test-config"
}

Now, unit testing can be run by using the standard npm command:

$ npm test

JUTA Ease-of-Use

JUTA's simplicity helps developers to focus on the test case itself, more than the structure of the test suite. Test suites are TypeScript classes that implement JUTA decorators to define a collection of test cases. Test classes are declared by using the @TestSuite decorator, as shown below:

Testing Asynchronous Code

Running code asynchronously is one of the most important parts of the modern JavaScript paradigm. JUTA makes testing asynchronous code as simple as testing synchronous code. By adding the @Async decorator to the callback parameter of a test method, you indicate that the test case must be invoked asynchronously:

More to Come...

We have planned to add parameterized tests to the JUTA specification. This feature should be added to the API in the next release. The Tiger framework will be updated at the same time, to fit the specification.

Unlike JUnit, parameterized tests will not use constructor initialization. Indeed, we want JUTA classes to be Plain Old JavaScript Objects to ensure a better portability. Thus, parameterized tests will only use the declarations below:

The parametrized property of the @TestSuite decorator indicates whether the test suite is parametrized (true), or not (false, default).

The @Parameters decorator marks a method as being the parameters provider for the test suite.

The @Parameter decorator defines a parameter to be initialized by the test runner.

Referring to JUnit, the JUTA features should be enough to cover the whole spectrum of test cases. JUTA is an open specification, so improvement requests can be discussed by the community.

Summary

In this article, we have exposed a brief description of the JavaScript Unit Testing API. JUTA is a small part of the JEC project and the only one that can be used outside of a JavaScript container.

In the coming month, we will show you the GlassCat application server and many useful projects based upon the JEC philosophy: "Standardization and portability of JavaScript web applications."

For more guides and tutorials on how to use JUTA, check out the GitHub page!

For an early preview of GlassCat and the JEC project, please go to the project pages.