Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TestNG - Gettting error [ClassHelper] Could not instantiate

 
Anoop Nair
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem :)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic