In our previous post we reviewed general purpose testing tools. Today we are going to review tools for modular and integration testing.
The first thing that is probably worth choosing when searching for suitable testing tools is the framework and libraries to support it. It is recommended to use what the selected framework provides as long as there is no need for unique tools. Here are some general guidelines:
- If you are looking for a certain starting point, or you need a fast framework for a large project, choose Jest.
- If you are interested in the flexibility and extensibility of the configuration – take a look at Mocha.
- If you want simplicity, try Ava.
- If you need control over low-level testing mechanisms – pay attention to the tape.
Here is a brief overview of the most famous tools in this category.
Mocha is currently the most widely used library. Unlike the Jasmine library, which we will discuss later, this library uses third-party assertion-building tools and external tools for creating imitations and spyware functions (usually Enzyme and Chai). This means some additional difficulties in setting up Mocha, and the fact that the resulting functionality will be divided between different libraries, but this framework is more flexible and expandable compared to Jasmine.
For example, if you need special assertion logic , you can fork Chai and replace only Chai in your toolbox with your own library for creating assertions. This can be done in Jasmine, but in Mocha this change will be more obvious.
Here are some features of Mocha that you should pay attention to:
- Community. Community forces have developed many plugins and extensions for use in unique test scenarios.
- Extensibility Plugins, extensions, and libraries that can be used with Mocha, such as Sinon, include features not found in Jasmine.
- Global variables Mocha, by default, creates test structures in global form. This does not apply to claims, imitations, spy functions, which distinguishes Mocha from Jasmine. To some, such heterogeneity of global objects seems illogical.
Jest is a testing framework developed by Facebook. It is based on Jasmine. As of today, Facebook has redesigned most of its functionality and has created many new features based on it.
It is worth noting that after analyzing the huge amount of materials on Jest, we can conclude that many developers are impressed with the speed and convenience of this framework. Among the features of Jest are the following:
- Performance. The first thing to say is that the Jest framework is recognized as the fastest in application to large projects with many test files due to the implementation of an intelligent parallel testing mechanism. We can confirm this by our own experience.
- User interface. The jest interface is clear and easy to use.
- Having everything you need to get started. The jest comes with assertions, spyware, and imitation tools that are equivalent to separate libraries, like Sinon, that perform the same functions. If the standard features do not suit you and you need something special, you can use third-party libraries.
- Global variables As in the case of Jasmine, Jest, by default, creates global test variables, so they do not need to be explicitly connected. This feature can be perceived as a disadvantage, because such an approach harms the flexibility of the tests and their ability to manage them, but in most cases it just simplifies the work.
- Testing with pictures. There is a jest-snapshot library that is developed by Facebook. It can be used to organize testing using snapshots (snapshot testing) in almost any other framework, for example, through a suitable plug-in.
- Improved module imitation. Jest simplifies the imitation of “heavy” modules, which allows to improve the speed of testing. For example, using Jest, you can create a “stub” for a service that performs a network request, which gives a much higher speed compared to the actual execution of the request.
- Analysis of code coverage tests. Jest has powerful and fast embedded test analysis code that is based on Istanbul .
- Reliability. Although Jest is a relatively young library, during 2017, a lot of work was done on its stability, and now it can be considered reliable. Now, for example, all major IDEs support it.
- Development. During project development, tests are performed very quickly due to the fact that the system monitors file changes and does not perform unnecessary actions.
Jasmine is the testing framework on which Jest is based. If there is a Jest – who might need Jasmine? The thing is that Jasmine appeared earlier than Jest, there are a huge number of publications on it, many tools have been created for it.
In addition, the creators of Angular still advise using Jasmine, not Jest, although Jest is great for testing Angular projects, and many use it for this. Here are the main features of Jasmine:
- Having everything you need to get started. Jasmine includes everything you need to start testing.
- Global variables In Jasmine, all important testing tools are available in the global scope.
- Community. Jasmine has existed since 2009, during which time many publications have been published on this framework. In addition, many Jasmine based tools have been created.
- Angular support. All versions of Angular support Jasmine, and it is this framework that recommends the official Angular documentation .
Ava is a minimalist test library that supports parallel test execution. Here are its main characteristics:
- Having everything you need to get started. Ava comes with everything you need to start testing (in addition to tools for creating spyware and imitations that are easy to integrate into Ava). Tests on Ava can be performed in the Node.js environment.
- Global variables As you can see from the above code fragment, the library does not create global variables, that is, the developer can better control what is happening.
- Simplicity. Ava is distinguished by a simple structure and a simple statement model. There is no overly complex API, but it supports many advanced features.
- Development. Ava is convenient to use in the development process, as the system allows you to quickly test the modified code …
- Speed. Tests are performed in parallel as separate Node.js processes.
- Testing with pictures. This feature is supported as part of the framework.
Tape is the simplest testing framework considered here, with a small and clear API. This is a regular JS file that works in Node.js. Here are the main characteristics of the tape:
- Simplicity. The minimalist structure of tests and statements, the absence of a complex API. Everything is arranged even easier than in Ava.
- Global variables Global variables are not created, it gives the opportunity to better control the test.
- Lack of general condition. Tape does not welcome the use of functions like
beforeEach, which reflects the desire for modularity tests and to ensure maximum control over the testing process.
- No need for command line interface. The tape library is capable of working wherever JS can run.
Interesting links: general purpose testing tools
About The Author: Yotec Team
More posts by Yotec Team