首页 > 解决方案 > 在来自 Karma-JUnit-Reporter 的 JUnit xml 文件中包含文件名

问题描述

我需要找到一种方法在 JUnit XML 结果文件中包含某个测试的文件名。它只包含类名:

<testcase name="xxxTest should do Y." time="0.119" classname="Chrome_80_0_3987_(Mac_OS_X_10_12_6).xxxTest">

classNameFormatter在文件中创建报告配置时有一个选项可以传入karma.conf.js,但不确定是否有办法使用它来检索文件名?

// karma.conf.js

// the default configuration
junitReporter: {
  outputDir: '', // results will be saved as $outputDir/$browserName.xml
  outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile
  suite: '', // suite will become the package name attribute in xml testsuite element
  useBrowserName: true, // add browser name to report and classes names
  nameFormatter: undefined, // function (browser, result) to customize the name attribute in xml testcase element
  classNameFormatter: undefined, // function (browser, result) to customize the classname attribute in xml testcase element
  properties: {}, // key value pair of properties to add to the <properties> section of the report
  xmlVersion: null // use '1' if reporting to be per SonarQube 6.2 XML format
}

标签: javascriptjunitjasminekarma-runner

解决方案


你可以这样做:

classNameFormatter: function(browser, result) {
    return result.suite[0];
}, 

您可以记录输入(浏览器和结果)的结构,以了解您拥有哪些数据:

console.dir(result);

希望能帮助到你!


推荐阅读