Getting java.lang.NullPointerException errors while running testng.xml
I am getting following error while running 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
my testng.xml looks like :
<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>
my build.xml file is:
<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" />
<开发者_JAVA技巧/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" />
Can anybody help me...why I am getting this error. Your help will be appreciated
It looks like the problem is that that is not a testng XML file. It is an Ant build file.
For information on what a real testng XML file should look like, see here. Alternatively, rename the file and use Ant to run the tests; e.g.
$ mv testng.xml build.xml
$ ant test
However, it is curious that testng fails in such a spectacular way when you give it an XML file that it doesn't grok. Insufficient testing perhaps? :-)
Looks to me as if it can't find your testng.xml
file. That's one possible reason for a NPE thrown by a XML Parser: a null
input. I see that ant
defaults to build.xml
. Do you have a build.xml
file too?
Look at the run_testNG
script, may be you can/have to add a full path to your file.
I had the same problem,
but found I was picking up a dbUnit dataset file that happend to match the pattern I had set up to pick up testng xml file (*test.xml).
Simply renamed the file and I was good to go.
Hope this helps, even though the question was asked a while ago.
精彩评论