mocha-junit-reporter npm地址
mocha-junit-reporter github地址
生成 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下向报表添加属性。如果您希望您的CI环境为分析目的添加报表的额外构建道具,这将非常有用。
这样做通过env变量传递它们:
或
结果XML文件名可以包含[hash],例如/path_to_your/test-results.[hash].xml。[hash]由测试结果XML的MD5哈希替换。这支持在多个文件中并行执行多个mocha-junit-reporter的编写测试结果。
为了显示完整的组别标题(包括parents),只需指定testsuitesTitle选项.
如果希望切换生成的testCase XML条目的classname和name,可以使用testCaseSwitchClassnameAndName选项。
下面是使用testCaseSwitchClassnameAndName选项的XML输出示例:
<testcase name="should behave like so" classname="Super Suite should behave like so">
<testcase name="Super Suite should behave like so" classname="should behave like so">
还可以通过设置reporterOptions.testsuitesTitle来配置testsuites.name属性,并通过设置reporterOptions.testsuitesTitle来配置根suite的name属性。
configures the file to write reports to
if set to a truthy value pending tests will be included in the report
a hash of additional properties to add to each test suite
if set to a truthy value the produced XML will be logged to the console
if set to a truthy value nested suites' titles will show the suite lineage
the character to use to separate nested suite titles. (defaults to ' ')
testCaseSwitchClassnameAndName
set to a truthy value to switch name and classname values
the name for the root suite. (defaults to 'Root Suite')
the name for thetestsuitestag (defaults to 'Mocha Tests')