Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

TestNG - Gettting error [ClassHelper] Could not instantiate

 
Ranch Hand
Posts: 70
  • Likes 1
  • 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??
 
Author
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem :)
 
BWA HA HA HA HA HA HA! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic