gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 05:21:35 24 4
gpt4 key购买 nike

我尝试在我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com