Cypress

Cypress is a testing framework for Webapps.

Enabling XML Output

Cypress can be configured to produce JUnit XML output by adding the mocha-junit-reporter package to your codebase and modify the config file to add it as a reporter.

npm install --save-dev mocha-junit-reporter

cypress.config.js or similar file.

const { defineConfig } = require('cypress')
module.exports = defineConfig({
  reporter: 'junit',
  reporterOptions: {
    mochaFile: 'results/my-test-output.xml',
  },
})

Now you can run Cypress from the command line with

cypress run

And from within your CI system the same way

cypress run

Test Suite Naming

The mocha-junit-reporter will automatically fill in values for the and name and class attributes.

describe('addition', () => {
  describe('positive numbers', () => {
    it('should add up', () => {
      expect(1 + 2).toBe(3);
    });
  });
});

would produce output that looks like this:

<testsuites name="Mocha Tests">
  <testsuite name="addition">
    <testcase classname="addition positive numbers should add up" 
              name="addition positive numbers should add up">
    </testcase>
  </testsuite>
</testsuites>

The default attributes can be configured with the reporterOptions argument in the Cypress config.

Last updated