[testng-dev] BUG: Non UTF-8 byte sequence in junitreports XML

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[testng-dev] BUG: Non UTF-8 byte sequence in junitreports XML

Alexey Krylov
Hi,

I'm using testng with Jenkins running on Tomcat. Unfortunately, TestNG Results Plugin for Jenkins suffers from multiple bugs and usability issues, so I have to use JUnit Reports plugin running off junitreports produced by testng. But testng produces a invalid UTF-8 encoded xml reports with raw character data coming from assertions. For example, the following assertion

public void testOne() {
    char ch = (char)0xC0;
    Assert.assertEquals(ch, 'x');
}

will cause generated junitreports/TEST-ReportTest.xml to include non  UTF-8 encoded string. The fix is really just one line in JUnitReportReporter.java:


diff --git a/src/main/java/org/testng/reporters/JUnitReportReporter.java b/src/main/java/org/testng/reporters/JUnitReportReporter.java
index a3122d1..237b32e 100644
--- a/src/main/java/org/testng/reporters/JUnitReportReporter.java
+++ b/src/main/java/org/testng/reporters/JUnitReportReporter.java
@@ -171,7 +171,7 @@ public class JUnitReportReporter implements IReporter {
       xsb.pop("testsuite");

       String outputDirectory = defaultOutputDirectory + File.separator + "junitreports";
-      Utils.writeFile(outputDirectory, getFileName(cls), xsb.toXML());
+      Utils.writeUtf8File(outputDirectory, getFileName(cls), xsb.toXML());
     }

 //    System.out.println(xsb.toXML());
 

Thank you
--Alexey

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] BUG: Non UTF-8 byte sequence in junitreports XML

Cédric Beust ♔-2
Hi Alexey,

I just fixed this in master, thanks!


-- 
Cédric



On Fri, Apr 19, 2013 at 8:24 AM, Alexey Krylov <[hidden email]> wrote:
Hi,

I'm using testng with Jenkins running on Tomcat. Unfortunately, TestNG Results Plugin for Jenkins suffers from multiple bugs and usability issues, so I have to use JUnit Reports plugin running off junitreports produced by testng. But testng produces a invalid UTF-8 encoded xml reports with raw character data coming from assertions. For example, the following assertion

public void testOne() {
    char ch = (char)0xC0;
    Assert.assertEquals(ch, 'x');
}

will cause generated junitreports/TEST-ReportTest.xml to include non  UTF-8 encoded string. The fix is really just one line in JUnitReportReporter.java:


diff --git a/src/main/java/org/testng/reporters/JUnitReportReporter.java b/src/main/java/org/testng/reporters/JUnitReportReporter.java
index a3122d1..237b32e 100644
--- a/src/main/java/org/testng/reporters/JUnitReportReporter.java
+++ b/src/main/java/org/testng/reporters/JUnitReportReporter.java
@@ -171,7 +171,7 @@ public class JUnitReportReporter implements IReporter {
       xsb.pop("testsuite");

       String outputDirectory = defaultOutputDirectory + File.separator + "junitreports";
-      Utils.writeFile(outputDirectory, getFileName(cls), xsb.toXML());
+      Utils.writeUtf8File(outputDirectory, getFileName(cls), xsb.toXML());
     }

 //    System.out.println(xsb.toXML());
 

Thank you
--Alexey

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] BUG: Non UTF-8 byte sequence in junitreports XML

Peter Gorwa
This post has NOT been accepted by the mailing list yet.
Hi,

same problem in testng-results.xml
Failed to read test report file target\failsafe-reports\testng-results.xml
org.dom4j.DocumentException: Invalid byte 2 of 3-byte UTF-8 sequence. Nested exception: Invalid byte 2 of 3-byte UTF-8 sequence.

patch for src/main/java/org/testng/reporters/XMLReporter.java

@@ -95,11 +95,11 @@ public class XMLReporter implements IReporter {
   private void writeSuiteToFile(File suiteFile, ISuite suite) {
     XMLStringBuffer xmlBuffer = new XMLStringBuffer();
     writeSuiteToBuffer(xmlBuffer, suite);
     File parentDir = suiteFile.getParentFile();
     if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {
-      Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());
+      Utils.writeUtf8File(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML());
     }
   }
 
   private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {
     String relativePath = suite.getName() + File.separatorChar + FILE_NAME;

Thanks
Peter