testng-results.xml was not completely generated.
See original GitHub issueTestNG Version
6.9.13.6 Java 1.8.0_74 linux x64
Actual behavior
As we run tests on Jenkins, and display test report by TestNG jenkins plugin. After update version of TestNG to 6.9.13.6, and version of java to 1.8.0_74, there are errors occured.
Logs of TestNG jenkins plugin:
TestNG Reports Processing: START Looking for TestNG results report in workspace using pattern: **/testng-results.xml Saving reports… Processing ‘/var/jenkins_home/jobs/api-test_payment_app-payment_0001_brood-qa13_daily/builds/679/testng/testng-results.xml’ Failed to parse XML: CDATA section started on line 1302 and column 26 was not closed (position: TEXT seen …<value>\n <![CDATA[org.testng.TestRun… @1302:44) caused by: java.io.EOFException: no more data available - expected end tags </value></param></params></test-method></class></test></suite></testng-results> to close start tag <value> from line 1301 and start tag <param> from line 1300 and start tag <params> from line 1299 and start tag <test-method> from line 1298 and start tag <class> from line 1289 and start tag <test> from line 8 and start tag <suite> from line 5 and start tag <testng-results> from line 2, parser stopped on TEXT seen …<value>\n <![CDATA[org.testng.TestRun… @1302:44 org.xmlpull.v1.XmlPullParserException: CDATA section started on line 1302 and column 26 was not closed (position: TEXT seen …<value>\n <![CDATA[org.testng.TestRun… @1302:44) caused by: java.io.EOFException: no more data available - expected end tags </value></param></params></test-method></class></test></suite></testng-results> to close start tag <value> from line 1301 and start tag <param> from line 1300 and start tag <params> from line 1299 and start tag <test-method> from line 1298 and start tag <class> from line 1289 and start tag <test> from line 8 and start tag <suite> from line 5 and start tag <testng-results> from line 2, parser stopped on TEXT seen …<value>\n <![CDATA[org.testng.TestRun… @1302:44
And open the testng-results.xml, the file is interrupted. In some jobs, the result file is generated completely. In some other jobs, the result file is interrupted on anywhere. It may end with incomplete CDATA “TestRunner”, or end with a “</class>” tag.
Diagnosis
I created a help class to test which part of logic is wrong.
public class XmlReportDiagnosis implements IReporter {
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
Logger.info(this.getClass(), "generateReport");
TestNG testNG = TestNG.getDefault();
if (!CollectionUtils.isEmpty(testNG.getReporters())) {
for (Iterator<IReporter> iterator = testNG.getReporters().iterator(); iterator.hasNext();) {
IReporter reporter = iterator.next();
if (reporter instanceof XMLReporter) {
XMLReporter xmlReporter = (XMLReporter) reporter;
try {
Field rootBufferField = reporter.getClass().getDeclaredField("rootBuffer");
rootBufferField.setAccessible(true);
XMLStringBuffer rootBuffer = (XMLStringBuffer) rootBufferField.get(xmlReporter);
if (null != rootBuffer) {
Logger.info(this.getClass(), rootBuffer.toXML());
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
}
}
In this class, it would print the rootBuffer, a field of XmlReport, to have a preview about whether the content in memory was generated completely. The test result is, the content in memory is correct.
So the cause was located to
Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer, null /* no prefix */);
The last line of XmlReport.generateReport. I created a new Reporter and replace the output logic with lib apache-commons-lang. It works now.
Issue Analytics
- State:
- Created 7 years ago
- Comments:37 (1 by maintainers)
It’s on Maven Central: http://repo1.maven.org/maven2/org/testng/testng/6.10/
– Cédric
On Thu, Dec 8, 2016 at 12:39 AM, alessio_demichelli < notifications@github.com> wrote:
You should try to ask your question on stackoverflow or maybe on the surefire issue tracker.