为什么TestNG会抛出“javax.xml.parsers.ParserConfigurationException:不支持验证”错误

时间:2017-12-13 23:02:12

标签: ant xml-parsing testng

将我的TestNG实现从6.11升级到6.13.1后出现错误。我有一个ANT构建(尝试在ANT 1.9.4和1.10.1上构建同样的失败),触发包含一个类的TestNG套件。完成所有ANT设置后,它调用TestNG开始测试执行,我立即得到以下错误:

[testng] javax.xml.parsers.ParserConfigurationException: validation is not supported
[testng]    at org.gjt.xpp.jaxp11.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:100)
[testng]    at org.testng.xml.XMLParser.<clinit>(XMLParser.java:29)
[testng]    at org.testng.xml.Parser.<clinit>(Parser.java:34)
[testng]    at org.testng.TestNG.parseSuite(TestNG.java:290)
[testng]    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:334)
[testng]    at org.testng.TestNG.initializeEverything(TestNG.java:974)
[testng]    at org.testng.TestNG.run(TestNG.java:988)
[testng]    at org.testng.TestNG.privateMain(TestNG.java:1330)
[testng]    at org.testng.TestNG.main(TestNG.java:1299)
[testng] [TestNG] [ERROR] java.lang.NullPointerException
[testng] Exception in thread "main" java.lang.NullPointerException
[testng]    at org.testng.TestNG.getStatus(TestNG.java:206)
[testng]    at org.testng.TestNG.main(TestNG.java:1300)
[testng] The tests failed.

这是我的build.xml:

<project name="6 - GW Testing" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="lib.dir" location="C:/dev/.ivy2/cache" />
<property name="res.dir" location="../TestNGReports" />
<property name="GWPersistence.ivy.file" value="C:/tmp/svncheckouts/guidewire/GWPersistenceIvy/gwpersistence-ivy.xml"/>
<property name="GWBroker.ivy.file" value="C:/tmp/svncheckouts/guidewire/GWBrokerIvy/gwbroker-ivy.xml"/>
<property name="GWRepository.ivy.file" value="C:/tmp/svncheckouts/guidewire/GWRepositoryIvy/gwrepository-ivy.xml"/>
<property name="GWServices.ivy.file" value="C:/tmp/svncheckouts/guidewire/GWServicesIvy/gwservices-ivy.xml"/>
<property name="GWTesting.ivy.file" value="C:/tmp/svncheckouts/guidewire/GWTestingIvy/gwtesting-ivy.xml"/>
<property name="Local.config" location="C:/tmp/regression-configs/guidewire" />
<property name="Regression.config" location="${Local.config}/suite" />

<path id="lib.classpath">
    <fileset dir="${lib.dir}">
        <include name="**/*.jar" />
    </fileset>
</path>

<path id="combined.classpath">
    <path refid="lib.classpath" />
</path>

<target name="init" description="initialize the build environment">
    <tstamp />

    <delete dir="${res.dir}" />
    <mkdir dir="${res.dir}" />

    <delete dir="C:/Users/qauser/.ivy2/cache/com.idfbins.guidewire" />
</target>

<target name="resolve" depends="init" description="retrieve dependencies with ivy">
    <ivy:configure file="C:/dev/.ivy2/ivysettings.xml" />

    <ivy:resolve file="${GWPersistence.ivy.file}" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />

    <ivy:resolve file="${GWBroker.ivy.file}" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />

    <ivy:resolve file="${GWRepository.ivy.file}" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />

    <ivy:resolve file="${GWServices.ivy.file}" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />

    <ivy:resolve file="${GWTesting.ivy.file}" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />

    <ivy:resolve file="../GWRepositoryConfig/suite/ivy.xml" />
    <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact]-[type]-[revision].[ext]" />
</target>

<target name="run-tests-a-test-runner" depends="resolve">
    <taskdef name="testng" classpathref="lib.classpath" classname="org.testng.TestNGAntTask">
        <classpath>
            <pathelement location="../../lib/default/testng-6.11.jar"/>
        </classpath>
    </taskdef>

    <delete file="${Local.config}/config.properties" />
    <copy file="C:/tmp/svncheckouts/guidewire/GWRepositoryConfig/suite/regression-test-runner.properties" todir="${Local.config}" />
    <rename src="${Local.config}/regression-test-runner.properties" dest="${Local.config}/config.properties"/>
    <echo message="CONFIG FILE: regression-test-runner.properties copied to config.properties" />

    <echo message="Running Tests..." />
    <testng classpathref="combined.classpath" outputDir="${res.dir}" haltOnfailure="false">
        <classpath location="combined.classpath" />
        <xmlfileset dir="C:/tmp/svncheckouts/guidewire/JobXMLFiles" includes="a-test-runner.xml"/>
    </testng>
  </target>
</project>

这是我的套件声明:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="A-Test-Runner" verbose="1">
<test name="A-Test-Runner">
    <classes>
        <class name="regression.r2.clock.billingcenter.cancel.TestCancellationOnBoundPolicy" />
    </classes>
</test>

到目前为止,我已经尝试删除套件声明中的DTD,我已经改变了每个方向的路径,并尝试了各种版本的ANT和TestNG。到目前为止,我唯一能够开始工作的是恢复到TestNG 6.11。我不知道这里发生了什么。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

看起来您的CLASSPATH正在将您解析为导致此问题的外部解析器。我想你可能正在解决pull-parser

我这样说是因为我看到了

at org.gjt.xpp.jaxp11.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:100)

在你的例外中。

您可以通过强制Java通过

指定它来回退到JDK中可用的默认解析器来尝试解决此问题。

-Djavax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl