Setup and Teardown

Example without setup/teardown

Class Name – beforeAndAfterEach.js


In above example it is failing because num value got increased in 1st test case. Below is how we can solve that by adding beforeEach which run for every test case.

Mocha and Chai


  • Mocha is a JavaScript Test Framework.
  • Runs on Node.js and Browser
  • Installation: (Run the below commands in terminal or cmd)

—- global helps to install the Mocha on the computer at a global level which helps to run the mocha test through the command line.

—- save-dev helps to add the mocha as a dependency in the package.jsonfile for that particular project.



  • Chai is BDD/TDD assertion library.
  • Can be paired with any javascript testing framework.
  • Assertion with Chai provides natural language assertions, expressive and readable style.
  • Installation: (Run the below commands in terminal or cmd)


Example: test.js


Command to run

How to setup JMeter and run web services

  • Download the JMeter from the site –
  • After extracting go inside the bin folder and run the ApacheJMeter executable jar file.
  • Now JMeter will get open.
  • Create a test plan and add the thread groups by selecting Add->Threads(Users)-> Thread Group.
  • Add the HTTP Header Manager by Right Click on Thread Group->Add->Config Element->HTTP Header Manager.
  • Add the Headers like Content-Type:application/json
  • Inside Thread group add HTTP sample by selecting Add->Sampler->HTTP Request
  • Make an HTTP request. Refer to the screenshots
  • Make the parameterization of email id and password by ${email} and ${password}.
  • Add the CSV Data Set Config ,Add->Config Element -> CSV Data Set Config for passing the values from CSV file to parameterized variables.
  • Place the CSV file inside the bin folder of JMeter and pass the name of the file.
  • Define the variable names
  • Pass the Delimiter used in CSV file
  • Add the JSON Extractor inside the HTTP Request by  Right Click on HTTP Request->Add->Post Processors->JSON Extractor
  • Add the json path of the keys that you want to extract and store it in a variable like $.data[*].id value from json will get the store in student_id variable.
  • Add the assertion in the response by Right Click on HTTP Request->Add->Assertions->Response Assertions
  • You can select any assertion type like Response code, Response Message etc. In the above screenshot, I have added the assertion for Response code that should be equal to the 200
  • Add the Results listener by Add->Listener->View Results Tree
  • Add the Summary report by Add->Listener->Summary Report
  • Now Run the script and see the results under Results and Report under Summary Reports.