Overview

In this tutorial, we will create some tests in JavaScript using Mocha and the "mocha-junit-reporter" module.

Requirements

  • Install "mocha" and "mocha-junit-reporter" modules

npm install -g mocha
npm install -g mocha-junit-reporter


Description


var assert = require('assert');
describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal(-1, [1,2,3].indexOf(4));
    });
  });
});


After running the tests and generating the JUnit XML report (e.g., test-results.xml), it can be imported to Xray (either by the REST API or through Import Execution Results action within the Test Execution).

 mocha test --reporter mocha-junit-reporter


JUnit's Test Case is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the value of the "it" concatenated with the several "describe" that make up the test case.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to the value of the last "describe" of the test.


References