Mocha Starting from arguably the most popular library

March 18, 2019 0 Comment

Starting from arguably the most popular library, Mocha. It is a JavaScript testing framework which runs tests on Node.js. It got the attention while deciding upon what testing framework should be used for UI tests mostly because of the fact that it supports BDD and because of its popularity and huge developer community. Mocha has been used to test everything under the sun, including functional UI testing so the decision to take a closer look at this framework from the perspective of functional testing was made. Mocha as a biggest testing framework is compatible with most (if not all of them) browser automation tools like Selenium, Protractor, WebdriverIO, etc.

By default mocha provides BDD style interface, which specifies a way to structure the code into test suites and test cases modules for execution and for the test report.
Mocha’s tests suites are defined by the `describe` clause and the test case is denoted by the `it` clause. Both clauses accept callback functions and can nest inside each other, which means that one test suite can have many inner test suites which can either contain another test suites or the actual test cases. The API provides developers with hooks like: `before()`, `after()`, `beforeEach()`, and `afterEach()` which are used for setup and teardown of the test suites and test cases. Mocha allows also to use any library for assertions such as ChaiJS or Should.js which are great BDD assertion libraries. This is very useful for unit tests or for functional tests that are going to be seen only by developers, but may not be preferred format for business-facing users. Test specification mixes up with the actual implementation of tests and it is not an especially friendly approach for non programmers and could actually complicate communication between both sides.