wood burning stoves 2.0*
The moose likes Testing and the fly likes TestNG - Gettting error [ClassHelper] Could not instantiate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "TestNG - Gettting error [ClassHelper] Could not instantiate" Watch "TestNG - Gettting error [ClassHelper] Could not instantiate" New topic
Author

TestNG - Gettting error [ClassHelper] Could not instantiate

Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Hi All....

I created a test case using TestNG and am trying to run it using Ant.
I am using TestNG version 5.8 and java 1.4.

I put my test-case in a package called tests. And made a jar out of it. The jar is put in the classpath.

Now when I run the case, I get the error: [testng] [ClassHelper] Could not instantiate.


My testng.xml is below:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Demo TestNG" parallel="methods" thread-count="7" >
<test name="Demo TestNG">
<classes>
<class name="tests.TestDemo">
<methods>
<include name="firstTest" />
</methods>
</class>
</classes>
</test>
</suite>



I also tried changing the testng.xml to work for packages as below:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Demo TestNG" parallel="methods" thread-count="7" verbose="3" >
<test name="Demo TestNG">
<packages>
<package name="tests" />
</packages>
</test>
</suite>




My test case is below:

package tests;

public class TestDemo
{
/*
* @testng.test
*/
public void firstTest() {
System.out.println("Hello");
}
}




Below is my Ant build.xml

<project name="Demo TestNG" basedir="." default="run-tests">
<property name="classes.dir" value="../classes" />
<property name="test.src.dir" value="../src"/>

<path id="testngLoc">
<fileset dir="../lib" includes="lib/testng.jar"/>
</path>
<path id ="testCaseLoc">
<fileset dir="../lib" includes="lib/testCases.jar"/>
</path>

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="testngLoc"/>

<target name="run-tests">
<echo message="running tests"/>
<testng classpathref="testngLoc" outputDir="." sourcedir="${test.src.dir}" verbose="2">
<classpath>
<pathelement path="${testCaseLoc}"/>
</classpath>
<xmlfileset dir="." includes="testng.xml" />
</testng>
</target>
</project>



Below is the stacktrace of the error:



Could someone tell what I am missing??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

How come you used quote tags for code, and code tags for output :(

<fileset dir="../lib" includes="lib/testCases.jar"/>

Wouldn't that resolve to ../lib/lib/testCases.jar?
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Oops.... I guess i missed the formatting part....
Thanks for reminding...

And yes .... that fileset did resolve to ../lib/lib/testCases.jar. That was the mistake.
I changed it to <fileset dir="../lib" includes="testCases.jar"/> and it worked....

Thanks a lot....


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No problem :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TestNG - Gettting error [ClassHelper] Could not instantiate