mocha-junit-reporter

mocha-junit-reporter npm地址arrow-up-right

mocha-junit-reporter github地址arrow-up-right

生成 JUnit-style 的XML测试结果。

安装

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

或者作为一个全局模块

$ npm install -g mocha-junit-reporter

运行mocha与 mocha-junit-reporter:

$ mocha test --reporter mocha-junit-reporter

这将在./test-results.xml输出结果文件。可以通过设置环境变量``MOCHA_FILE```或在mochaFile`中指定reporterOptions,可选地设置XML文件结果的替代位置:

$ MOCHA_FILE=./path_to_your/file.xml mocha test --reporter mocha-junit-reporter

$ mocha test --reporter mocha-junit-reporter --reporter-options mochaFile=./path_to_your/file.xml

var mocha = new Mocha({
    reporter: 'mocha-junit-reporter',
    reporterOptions: {
        mochaFile: './path_to_your/file.xml'
    }
});

向testsuite追加属性

还可以在testsuite下向报表添加属性。如果您希望您的CI环境为分析目的添加报表的额外构建道具,这将非常有用。

这样做通过env变量传递它们:

结果报告

结果XML文件名可以包含[hash],例如/path_to_your/test-results.[hash].xml[hash]由测试结果XML的MD5哈希替换。这支持在多个文件中并行执行多个mocha-junit-reporter的编写测试结果。

为了显示完整的组别标题(包括parents),只需指定testsuitesTitle选项.

如果希望切换生成的testCase XML条目的classnamename,可以使用testCaseSwitchClassnameAndName选项。

下面是使用testCaseSwitchClassnameAndName选项的XML输出示例:

value

XML output

true

<testcase name="should behave like so" classname="Super Suite should behave like so">

false(default)

<testcase name="Super Suite should behave like so" classname="should behave like so">

还可以通过设置reporterOptions.testsuitesTitle来配置testsuites.name属性,并通过设置reporterOptions.testsuitesTitle来配置根suite的name属性。

全配置选项

Parameter

Effect

mochaFile

configures the file to write reports to

includePending

if set to a truthy value pending tests will be included in the report

properties

a hash of additional properties to add to each test suite

toConsole

if set to a truthy value the produced XML will be logged to the console

useFullSuiteTitle

if set to a truthy value nested suites' titles will show the suite lineage

suiteTitleSeparedBy

the character to use to separate nested suite titles. (defaults to ' ')

testCaseSwitchClassnameAndName

set to a truthy value to switch name and classname values

rootSuiteTitle

the name for the root suite. (defaults to 'Root Suite')

testsuitesTitle

the name for thetestsuitestag (defaults to 'Mocha Tests')

Last updated