首页 文章

在jasmine junitreport中,我如何为每个规范添加不同的类名

提问于
浏览
1

我使用茉莉花测试框架来测试我的节点方法 . 使用jasmine junitreport报告我将测试报告作为xml格式 . 但是在这个xml中所有spec类都有相同的名称我想更改这个类名 . 我怎么能这样做..

测试用例

describe('Test cases', function(){
 it('test1',function(){
  expect(true).toEqual(true);
 });
 it('test2',function(){
  expect(true).toEqual(true);
 });    
 });

结果

<?xml version="1.0" encoding="UTF-8" ?>
 <testsuites>
 <testsuite name="Test cases" timestamp="2013-10-25T10:24:25">
   <testcase classname="Test cases " name="test1" time="0.002"></testcase>
   <testcase classname="Test cases " name="test2" time="0"></testcase>
 </testsuite>
  </testsuites>

在上面的报告中,我如何为每个测试用例添加单独的类名

1 回答

  • 0

    假设您正在使用节点jasmine-reporter软件包,那么您可以更改代码以输出不同的类名 .
    node_modules\jasmine-reporters\src\jasmine.junit_reporter.js 文件中输出测试名称的行是

    spec.output = '<testcase classname="' + this.getFullName(spec.suite) +
                  '" name="' + escapeInvalidXmlChars(spec.description) + 
                  '" time="' + spec.duration + '">';`
    

    您可以更改 this.getFullName(spec.suite) 以输出您想要的任何名称 .

相关问题