1

Is there a way to add tags to test cases so that I can run a particular test case instead of running the complete suite? If yes, can someone help me how to do it.

eg.

describe("User Service - create and search user", function() {
    var data;

    parseData('/Users/ksachdeva/node_modules/chakram/ns/tests/user-service/requestBodies/createUser.csv', execute);

        function execute(data) {

        before('should create a user', function () {

            res = call.post(testConfig.APP_URL + testConfig.CREATE_USER, JSON.parse(data));
            return expect(res).to.have.json(function(json)  {
            userid = json.user.userid;
           console.log("API Response ----> " + JSON.stringify(json));
           });

        });

        });
    }
});

Thanks!

1 Answers1

5

The idea of Tagging in mocha is well described in this WIKI page.

The main idea is to use particular keywords in your test (i.e. in the parent describe block) and then use a filter option (grep) to run only those tests.

Here's the full list of mocha options.

From the CLI you can do:

$ mocha --grep <pattern>

Or

$ mocha -g <pattern> 

Programmatically you can do:

// Instantiate a Mocha instance.
var mocha = new Mocha({
  grep: <String|RegExp>
});

mocha.addFile( 'test.js' );
mocha.run();
MarcoL
  • 9,829
  • 3
  • 37
  • 50