Using JUnit 4 API, is there a way to get a handle to a method in a test class that are annotated with @Test
?
Here's what I am currently doing:
JUnitCore core = new JUnitCore();
Request request = Request.aClass(MyTest.class);
Result result = core.run(request);
if(result.wasSuccessful())
System.out.println("SUCCESS"); // or do something else
This code will run all tests in MyTest
. However, what I want is to just specify the test class name at the beginning (MyTest.class
) and do following in a loop:
- Get next
@Test
annotated test in the class. - Print details
- Run the test (possibly using
Request.method(MyTest.class, "myTestMethod")
I can perhaps use reflection to get the method names and check if they are annotated with Test, but wanted to see if the JUnit API already provides this functionality.