【问题标题】:org.testng.TestNGException:NullPointerException while making a customized reports by reportngorg.testng.TestNGException:NullPointerException 同时通过 reportng 制作自定义报告
【发布时间】:2014-12-08 06:56:37
【问题描述】:

我最近将此代码添加到我的 testng.xml 中

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

我正在使用以下 jar 文件

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

它给了我以下错误

 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)

我添加了上面的监听器希望制作自定义报告我在eclipse类路径中添加了reportng的jar文件?

那么我该如何解决这个错误呢?

我是否将 jar 文件添加到其他地方?

【问题讨论】:

    标签: java maven selenium testng reportng


    【解决方案1】:

    在 ant build.xml 中添加 testng 而不是添加

     <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>
    

    只需确保将所有 jar 文件放在一起即可。

    【讨论】:

      【解决方案2】:

      您收到此错误是因为您在套件外添加了 listeners 标签 您应该使用 testng.xml 如下

      <?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> 
      

      这对我来说很好用。我相信您的 xml 文件更改后您的问题将得到解决。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多