Here is the deal , I have  some existing TestNG  suites ,now I want to run these TestNG cases on the android itself.

Solving Library issues.

                                > TestNG itself has the jar files (Use TestNG-jdk1.5, since android is java 1.5, other library of TestNG may have implications , which I did not test) , and also it is dependant on couple others. Even my target code is dependent on few jar files, so I need to add this to the library path in order to build it. but that is not it. I should also avail these libraries to the runtime as well, so for that I had to add the TestNG.jar , xmlbean.jar and my own other jars into the project/libs folder.

                                                Do note that android discourages this practice, however, my test classes will not run on the client machine ( phones) , so I don't worry too much.Another point I must mention here, don't include jar , external jars inside libs folder which has package starts with java.* or javax.* that makes the build and run on emulator /phone unhappy complaining about it with the error: Conversion to Dalvik format failed with error 1. Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.                                  

Copying TestNG case classes:

                                                You could add your test case classes very well in your src folder , or you can create additional source folder through eclipse and copy your existing test classes.

                               

Copying TestNG.xml

                My project has the TestNG.xml for the TestNG suite descriptor , so I need that too, but question was where to put it . I decided to put it inside assets folder

                               

Hooking TestNG run:

                                Well, I am not using ant to trigger the TestNG , so I must do the triggering the run through code. But where? What about the Main activity.

                               

                                 public class HelloTestNG extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { TestNG tng = new TestNG(); List l=null; try{ Resources r= this.getResources(); l= new Parser(this.getAssets().open("TestNG.xml")).parseToList(); }catch(Exception e){ System.out.println("Error loading TestNG.xml file"); e.printStackTrace(); } tng.setXmlSuites(l); // you need to set the output directory explicitly without which you would get FileNotFoundException when testng will // try to generate the reports tng.setOutputDirectory("/data/reports"); //just make sure this folder exists (create it) before running this or use the assets folder, and change the code accordingly tng.run();

                There.

Don't want to explain the code. The Android way of reading the xml file, and the TestNG way of  executing the test cases from the xml file though programming.

 Now everything is set  lets run it . You can pull the reports once you done from the device by "adb pull" command or use eclipse's filesystem android view.

                                Happy TestNG !!!!!