1

My code to get @Test annotated method names for a single class using Java:

public class AccountsTest
{

    @Test(dataProvider = "abc")
    public void login() {

    }

    @Test(dataProvider = "bbc")
    public void logout() {

    }

    public static void main(String args[]) {

        Annotation[] annotations = AccountsTest.class.getAnnotations(Test.class);
        Method[] methods = AccountsTest.class.getMethods();
        for(Method method:methods) {
            method.isAnnotationPresent(Test.class);
            System.out.println(method.getName());
        }
    }    
}

So How can I get all @Test annotated method names along with class names of entire project using Java?

Bosko Mijin
  • 3,287
  • 3
  • 32
  • 45
  • It sounds like http://stackoverflow.com/questions/862106/how-to-find-annotated-methods-in-a-given-package?rq=1 answers this question. – mkalkov Jul 14 '14 at 15:13
  • Beware of that question's accepted answer. It has two major mistakes: It assumes all classes are in files (as opposed to jar entries), and it assumes URL.getFile() returns a path which can be safely passed to the java.io.File constructor. – VGR Jul 14 '14 at 16:11
  • thank you for given link.thats i want – user3835762 Jul 15 '14 at 05:26
  • is above link work for both application jar(war) and source project? – user3835762 Jul 15 '14 at 06:10

0 Answers0