[testng-dev] Programatically running TestNG

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Programatically running TestNG

Natts
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

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

Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] Programatically running TestNG

Cédric Beust ♔-2
You need to add this jar file to your classpath (you can't modify your classpath at runtime).

-- 
Cédric




On Tue, Nov 1, 2011 at 1:11 PM, Natts <[hidden email]> wrote:
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

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


--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] Programatically running TestNG

Natts
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

--
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.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] Programatically running TestNG

Cédric Beust ♔-2
Natts,


-- 
Cédric




On Thu, Nov 3, 2011 at 9:59 AM, Natts <[hidden email]> wrote:
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

--
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.

To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Re: Programatically running TestNG

Dharshana kasun Warusavitharana
In reply to this post by Natts


On Wednesday, 2 November 2011 01:41:48 UTC+5:30, Natts wrote:
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

Hi Natts , 

I thinnk posts [1]and [2] can be useful to you.

--
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/-/NvlBQF8fWlsJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.