/April 05, 2015 12:13:43 A study of junit based on annotation and reflection:
Package Cn.seven.shengsiyuan.annocation.junitan;import Org.junit.test;public class Junitsource {//The question is why the main method is not written here, Method can be executed directly without being called?? -Reflection @testpublic void Hello () {System.out.println ("Hello World");}}
- First, get the class object corresponding to the classes you want to test.
- It then obtains the public decorated method array of the object by reflection
- Iterate over the array to get each method object
- Two methods for judging whether the method object is annotated
- Method object. isannotationpresent (annotation class. Class)
- The annotation class annotation class object =method object. getannocation (annotation class. Class).
- The method is then executed through Method.invoke.
Think in Java notes _chapter20_2_annocation and JUnit