

test_suite.js, and write to it the following describe("Inner Suite 1", function() ) A test suite teardown is denoted by ‘after’, while test case teardown is implemented by ‘afterEach’ function which are executed after a test suite and after each test case, respectively.Ĭreate a file that will ‘host’ the test suite, e.g. ‘beforeEach’ is actually a common setup for every case in the suite and will be executed before each case.Īs with the setup, Mocha supports test suite and test case teardown functions. A test suite setup is denoted by ‘before’ while a test case setup applies ‘beforeEach’. Mocha supports test suite setup and test case setup functions. Whereas, a test case is denoted by the ‘it’ function which accepts a callback function and contains the testing code. A test suite can contain child / inner test suites which can contain their own child test suites, etc. In Mocha, a test suite is defined by the ‘describe’ keyword which accepts a callback function. ‘–save’ option is used in order for the module to be installed in project’s scope and not globally. Install Chai Assertion Module npm install -save chai If mocha is to be used in CLI, then it should be installed globally as Nodejs. Mocha provides two modes for running: either by command line (CLI) or programmatically (Mocha API).

Mocha provides an API, which specifies a way to structure the testing code into test suites and test cases modules for execution and later on to produce a test report. In addition, Mocha has several similar compounds with Jasmine, another popular test automation framework which we’ve mentioned in our research for Front End and Unit Test Automation Trends. Mocha comes in the form of a Node package via ‘npm’ allowing to use any library for assertions as a replacement to Node’s standard ‘assert’ function, such as ChaiJS. Constructing Tests with Mocha Introduction to MochaĪs mentioned, Mocha is a Javascript test framework which runs tests on NodeJS. Integrating MochaJS with Selenium Webdriver 3ġ.Using Javascript Selenium 3 API Integrated with MochaJS Running Mocha’s Test Suite and Test CasesĢ.*Note: to get started with this Javascript tutorial, you’ll need to be familiar with the basics of NodeJS and Javascript programming language. These days, Javascript is a ubiquitous web language which seems to overcome it’s ‘notorious’ past and has become a more solid platform not only for client, but for server domains. Mochajs, or simply Mocha, is a feature rich JavaScript test framework running on Nodejs which provides the platform and the API for building standalone applications in the server side using the Google’s V8 Javascript engine at its base. In case you are looking to write a functional test in Javascript, the following tutorial provides a perfect structural and referential material for a UI automation engineer to Javascript testing with Selenium Webdriver 3, Mocha and NodeJS.
