运行 testng.xml 时出现以下错误
ant run_testNG
Buildfile: build.xml
run_testNG:
[testng] Exception in thread "main" java.lang.NullPointerException
[testng] at org.testng.xml.Parser.parse(Parser.java:189)
[testng] at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:351)
[testng] at org.testng.TestNG.run(TestNG.java:854)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1178)
[testng] at org.testng.TestNG.main(TestNG.java:1137)
[testng] The tests failed.
BUILD SUCCESSFUL
Total time: 0 seconds
我的 testng.xml 看起来像:
<project default="test">
<path id="cp">
<pathelement location="/softwares/lib/testng-5.13.1.jar"/>
<pathelement location="/softwares/cruisecontrol-bin-2.8.3/run_test/run_test/build"/>
</path>
<taskdef name="testng" classpathref="cp" classname="org.testng.TestNGAntTask" />
<target name="test">
<testng classpathref="cp" groups="fast">
<classfileset dir="build" includes="com/example/test/*.class"/>
</testng>
</target>
</project>
我的 build.xml 文件是:
<property name="lib.dir" value="/softwares/lib"/>
<property name="src.dir" value="/softwares/src" />
<target name="run_testNG" description="Run TestNG">
<testng classpathref="compile.classpath" haltOnfailure="false">
<xmlfileset dir="/softwares/cruisecontrol-bin-2.8.3/run_test/" includes="testng.xml" />
</testng>
</target>
<target name="start-server">
<java jar="/softwares/selenium/selenium-server-standalone-2.0b2.jar" fork="true" spawn="true">
<arg line="-timeout 30"/>
<jvmarg value="-Dhttp.proxyHost=proxy.corporate.com"/>
<jvmarg value="-Dhttp.proxyPort=3128"/>
</java>
</target>
<target name="stop-server">
<get taskname="selenium-shutdown"
src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer"
dest="result.txt" ignoreerrors="true" />
<echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
</target>
<taskdef resource="testngtasks" classpath="/softwares/selenium/selenium-2.0b2/libs/testng-5.14.1.jar" />
任何人都可以帮助我...为什么我会收到此错误。我们将不胜感激您的帮助
最佳答案
看起来问题在于这不是一个 testng XML 文件。它是一个 Ant 构建文件。
有关真实 testng XML 文件应是什么样子的信息,请参阅 here 。或者,重命名该文件并使用 Ant 运行测试;例如
$ mv testng.xml build.xml
$ ant test
<小时/>
然而,奇怪的是,当你给 testng 提供一个它不理解的 XML 文件时,它会以如此惊人的方式失败。或许是测试不够充分? :-)
关于java - 运行 testng.xml 时出现 java.lang.NullPointerException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5816270/