Trac不会解析google test xml输出文件

时间:2012-10-23 22:27:58

标签: c++ junit trac googletest

我运行了使用google test 1.6.0框架编写的单元测试,其中包含--gtest_output =“xml:test-results.xml”标志,并获得如下测试结果文件:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="8" failures="0" disabled="0" errors="0" time="81.396" name="AllTests">
  <testsuite name="TestSuite1" tests="8" failures="0" disabled="0" errors="0" time="81.396">
    <testcase name="Test1" status="run" time="6.391" classname="Class1" />
    <testcase name="Test2" status="run" time="6.1" classname="Class1" />
    <testcase name="Test3" status="run" time="7.146" classname="Class1" />
    <testcase name="Test4" status="run" time="16.164" classname="Class1" />
    <testcase name="Test5" status="run" time="25.145" classname="Class1" />
    <testcase name="Test6" status="run" time="6.099" classname="Class1" />
    <testcase name="Test7" status="run" time="6.162" classname="Class1" />
    <testcase name="Test8" status="run" time="8.187" classname="Class1" />
  </testsuite>
</testsuites>

基于我在其他帖子中读到的内容,gtest xml输出应该与junit解析器兼容。相关文章:Unable to get hudson to parse JUnit test output XML

错误的另一种可能性是我的被咬脚本。在Trac 0.12.2上运行。下面是我使用java:junit解析器解析XML文件的苦行方法:

<build xmlns:java="http://bitten.edgewall.org/tools/java">

   <step id="parse_results" description="Gather Results" onerror="fail">  
     <java:junit file="/home/user/temp/test-results.xml" />
   </step>

</build>

在trac中,它表示构建成功,但测试结果是空白的。 0运行,0失败,0忽略,0错误

感谢。

1 个答案:

答案 0 :(得分:1)

我能够解决问题。事实证明,Trac的JUnit解析器有一个bug。它不喜欢testsuites标签,它不喜欢有多个testsuite部分。 PHP允许testsuites标记,但不会执行多个文件。我选择在Python中创建一个解析器,从Gtest输出文件创建多个XML文件。

def move_results(results, results_dir):
    # Moves all results into a temp folder to be consumed by Bitten
    # Files with multiple test suite sections, split into individual files
    for files in results:
        fin = open(files)
        test_id = 0
        split_line = files.split('/')
        file_name = split_line[len(split_line)-1].split('.xml')
        for line in fin:
            if not 'testsuites' in line:
                if '<testsuite ' in line:
                    output_file = results_dir + file_name[0] + '-' + str(test_id) + '.xml'
                    test_id = test_id + 1
                    fout = open(output_file, 'w')
                    fout.write('<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n')
                    fout.write(line)
                elif '<testsuite\\>' in line:
                    fout.write(line)
                    fout.close()
                elif not '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n' in line:
                    fout.write(line)
        fin.close()
        os.remove(files)

或者,您可以使用Bitten使用XSLT进行转换。您还可以将输出文件合并为单个输出(使用nose的XUnit输出),并使用php:phpunit来解析文件。