Thursday, June 9, 2016

How to write Data Driven tests in Javascript

I know how to write "Parameterized tests" in Java and Data Driven tests in Groovy using Spock framework. But how to write in JavaScript? Now I try to show how to make it working using mocha framework.

Data Driven tests in Mocha is called "Dynamically generated tests", based on the API documentation, there are 2 steps:
  1) Create a test data array;
  2) Iterate the test data, generate the test case dynamically,  the test case name in "it" block is also generated dynamically, which is quite similar with Spock framework.

The implementation is pretty straight forward. Here is the example of my implementation in the Tennis Game Kata:
 The javascript example project is here:

Next step I will look at how to work it using Jasmine framework.