c++ - Sonar 无法读取我的 CPPUnit 报告

标签 c++ xml continuous-integration sonarqube cppunit

我尝试在我的 Sonar 中集成一个 CPPUnit 测试用例,但是当我放入报告时,解析出现问题。

# 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

然后,这里是生成 CPPUnit 报告的 C++ 代码:

#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++ 代码生成的报告:

<?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 在阅读这份报告时的回答:

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...:/ 我还通过生成 XML 报告成功地集成了 CPPCheck、RATS……但我没有使用 CPPUnit 进行管理

在此先感谢您的帮助,

最佳答案

关于c++ - Sonar 无法读取我的 CPPUnit 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40014189/

相关文章:

c++ - VMS 时间戳到 POSIX time_t --- Boost.DateTime 错误?

c++ - Web 服务器上的图像处理

java - CollapsingToolBar 不起作用后添加 ScrollView

html - 带有 servlet 的数据源 - javax.naming.NameNotFoundException

sql - 数据库持续集成 (CI) 的 Tarantino 替代方案?

continuous-integration - DialogFlow (API.AI),如何使用命令行部署/上传 JSON 以与 CI 一起工作?

c++ - std::unique_ptr constexpr 构造函数

c++ - ' ' seems to be treated as '\0'?

php - 在 PHP 中查找不匹配的标签时遇到问题

jenkins - 使用 jenkins 远程 glassfish 部署失败