org.testng.TestNGException:NullPointerException while making a customized reports by reportng

3.8k views Asked by At

I have recently added this code into my testng.xml

<listeners>      
  <listener class-name="org.uncommons.reportng.HTMLReporter"/>
       <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>

I am using the following jar files

velocity-dep-1.4.jar
reportng-1.1.4.jar
guice-3.0.jar

it is giving me the following error

 org.testng.TestNGException: java.lang.NullPointerException
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:341)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.NullPointerException
    at org.testng.xml.TestNGContentHandler.xmlListeners(TestNGContentHandler.java:356)
    at org.testng.xml.TestNGContentHandler.endElement(TestNGContentHandler.java:704)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endNamespaceScope(Unknown Source)

I added the above listener in hope to make customized reports I have added jar files of reportng in the eclipse classpath?

so how can i fix the error?

do I add the the jar files somewhere else?

2

There are 2 answers

0
vaibhavcool20 On BEST ANSWER

instead of adding in testng add in ant build.xml

 <testng classpath="class file path" suitename="suite1"
    outputDir="test output"    
    haltonfailure="true"
    useDefaultListeners="false"
    listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter"
    >   
        <xmlfileset dir="${ws.home}" includes="testng.xml"/>
        <sysproperty key="org.uncommons.reportng.title" value="Report"/>    
    </testng>

just make sure to keep all the jar files together.

0
Nilesh Barde On

You are getting this error because you have added the listeners tag outside the suite You should use the testng.xml as below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test"> 
    <listeners> 
        <listener class-name="org.uncommons.reportng.HTMLReporter"/>
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
    </listeners>    
    <test name="Round1">
        <classes>
            <class name="testcases.common.testCase"/>
        </classes>
    </test>
</suite> 

This is working fine for me. I am sure your problem will be resolved after making changes to your xml file.