package annotationTest;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface test {
String  value() default "had";}package annotationTest;import java.lang.reflect.Method;public class AnnotationTest
{
private static Object object;
public static void main(String[] args)throws Exception
{
Class<?> classtest = MyTestAnonotation.class;
Object obj = classtest.getConstructor(new Class[]{}).
newInstance(new Object[]{});
Method [] methods = classtest.getDeclaredMethods();

for(Method method:methods)
{
if(method.isAnnotationPresent(test.class))
{

method.invoke(obj,new Object[]{object});
}
}
}
}
JUnit测试