首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >声纳无法阅读我的CPPUnit报告

声纳无法阅读我的CPPUnit报告
EN

Stack Overflow用户
提问于 2016-10-13 06:52:57
回答 1查看 928关注 0票数 1

我试图在Sonar中集成一个CPPUnit测试用例,但是当我提交报告时,解析过程中出现了一个问题。

代码语言:javascript
复制
# must be unique in a given SonarQube instance
sonar.projectKey=test

# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=test

sonar.projectVersion=1.0

sonar.sources=./core/

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

sonar.language=c++

sonar.cxx.xunit.reportPath=cppunit-report.xml

sonar.cxx.rats.reportPath=rats-report.xml

sonar.cxx.cppcheck.reportPath=cppcheck-report.xml

然后,下面是c++代码,以生成CPPUnit的报告:

代码语言:javascript
复制
#include "PropositionalVariableTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION( PropositionalVariableTest );

int main(int argc, char* argv[])
{
    // informs test-listener about testresults
    CPPUNIT_NS::TestResult testresult;

    // register listener for collecting the test-results
    CPPUNIT_NS::TestResultCollector collectedresults;
    testresult.addListener (&collectedresults);

    // register listener for per-test progress output
    CPPUNIT_NS::BriefTestProgressListener progress;
    testresult.addListener (&progress);

    // insert test-suite at test-runner by registry
    CPPUNIT_NS::TestRunner testrunner;
    testrunner.addTest (CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest ());
    testrunner.run(testresult);

    // output results in compiler-format
    CPPUNIT_NS::CompilerOutputter compileroutputter(&collectedresults, std::cerr);
    compileroutputter.write ();

    // Output XML for Jenkins CPPunit plugin
    ofstream xmlFileOut("../cppunit-report.xml");
    XmlOutputter xmlOut(&collectedresults, xmlFileOut);
    xmlOut.write();

    // return 0 if tests were successful
    return collectedresults.wasSuccessful() ? 0 : 1;
}

然后,下面是由这个C++代码生成的报告:

代码语言:javascript
复制
<?xml version="1.0" encoding='ISO-8859-1' standalone='yes' ?>
<TestRun>
  <FailedTests></FailedTests>
  <SuccessfulTests>
    <Test id="1">
      <Name>PropositionalVariableTest::testInitCorrect</Name>
    </Test>
  </SuccessfulTests>
  <Statistics>
    <Tests>1</Tests>
    <FailuresTotal>0</FailuresTotal>
    <Errors>0</Errors>
    <Failures>0</Failures>
  </Statistics>
</TestRun>

最后,下面是SonarQube在阅读本报告时所回答的问题:

代码语言:javascript
复制
INFO: Sensor CxxXunitSensor
INFO: Scanner found '1' report files
INFO: Parser will parse '1' report files
INFO: Processing report '/.../cppunit-report.xml'
ERROR: Cannot feed the data into SonarQube, details: 'javax.xml.stream.XMLStreamException: ParseError at [row,col]:[16,1]
Message: Can not call 'getAttributeValue(): cursor does not point to a valid node (curr event [null]; cursor state CLOSED)'
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 18.886s
INFO: Final Memory: 57M/364M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution

我的问题是我完全不明白为什么会这样..。我的猜测是这份报告是用XML 1.0./我还通过生成一个CPPCheck报告,成功地集成了没有任何问题的大鼠.但我不想用CPPUnit

提前感谢你的帮助,

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-19 13:51:05

正如我们最终发现的那样,XML必须通过一些XSL转换成一种不同的格式,在这里为插件在站点上提供:

https://github.com/SonarOpenCommunity/sonar-cxx/blob/558a6c293a8bcd6434411f889957f938a6f2fb97/cxx-sensors/src/main/resources/xsl/cppunit-1.x-to-junit-1.0.xsl

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40014189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档