lundi 21 septembre 2015

How to set priority for test methods execution using TestNG + JAVA Reflection

I have trying to execute my test script with the help of reflections which has annotated as @Test as following way:

Class<?> className = Class.forName(format);  //Load the class name at runtime

                Constructor<?> customConstructor = className.getConstructor(WebDriver.class);   //Create customized constructor and initalize driver from testbase


Method[] method = className.getMethods();  //Call the list of methods in current class file

                for (Method me : method) {
                    if (me.getName().startsWith("test")) {   //Check wheather the class prefix as test

                        Method getMethods = Class.forName(format).getDeclaredMethod(me.getName());   //Loading all the methods at runtime.
                        if(getMethods.isAnnotationPresent(Test.class))
                        {
//The method which is annotated @Test will execute here, using invoke() method of reflection.
}
}

But, the problem is not able to run the @Test methods as per priority value. Its executing randomly. Can anybody tell me how could I run the @test methods based on priority value.





Aucun commentaire:

Enregistrer un commentaire