Programatically running TestNG

182 views
Skip to first unread message

Natts

unread,
Nov 1, 2011, 4:11:48 PM11/1/11
to testng-dev
I am trying to load a jar file and execute specific test classes using
testng. The following is the code...

XmlSuite suite = new XmlSuite();
suite.setName("TmpSuite");

XmlTest test = new XmlTest(suite);
test.setName("TmpTest");

List<XmlClass> classes = new ArrayList<XmlClass>();
classes.add(new XmlClass("myPackage.SampleTest"));

test.setXmlClasses(classes) ;

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);

TestNG tng = new TestNG();
tng.setTestJar("SampleTest.jar");
tng.setXmlSuites(suites);
tng.run();

Basically I am loading the jar file and trying to execute the
myPackage.SampleTest class using testng. However, when executed testng
is not recognizing the class in the jar file and throwing the
following error "Cannot find class in classpath:
myPackage.SampleTest"

Am I missing anything here....

Any help will be much appreciated.

Thanks,

Natts

Cédric Beust ♔

unread,
Nov 1, 2011, 4:15:26 PM11/1/11
to testn...@googlegroups.com
You need to add this jar file to your classpath (you can't modify your classpath at runtime).

-- 
Cédric





--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to testn...@googlegroups.com.
To unsubscribe from this group, send email to testng-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.


Natts

unread,
Nov 3, 2011, 12:59:27 PM11/3/11
to testn...@googlegroups.com
Hi Cedric,
 
Thanks for the response,  I added the jar file to the Thread.currentThread().setContextClassLoader(jatFile)  instead of using testng.setTestJara and it worked well.
 
I am trying to get list of test methods within a particular class programatically and I am unable to find a method in the testNG class that can help me with that. Any suggestions you have. Do I have to write my ownn code using reflections to do this or are there some classes in test ng that can help list the methods.
 
Thanks
 
Natts

Cédric Beust ♔

unread,
Nov 3, 2011, 1:34:11 PM11/3/11
to testn...@googlegroups.com
Natts,


-- 
Cédric




 
Natts

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-dev/-/t39-4jy_ep4J.

Dharshana

unread,
Dec 2, 2012, 8:19:42 PM12/2/12
to testn...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages