uiautomator 自定义注解的应用

自定义注解tester

@Target({java.lang.annotation.ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Tester {
    public abstract String value() default "无名氏";
}

在testcase中引用

@Tester("zhangsan")
    public void test004() throws IOException, AutoException,
            UiObjectNotFoundException, NotRootException, RemoteException {

在结果统计中应用

public String getTester(){
         Tester tester = (Tester)getTestCaseAnnotation(Tester.class);
          return ((tester != null) ? tester.value() : "");        
    }
    
      private <T extends Annotation> T getTestCaseAnnotation(Class<T> clazz) {
            try {
              if (getClass().isAnnotationPresent(clazz))
                return getClass().getAnnotation(clazz);

              Method method = getClass().getMethod(getName(), new Class[0]);
              if (method.isAnnotationPresent(clazz))
                return method.getAnnotation(clazz);
            }
            catch (NoSuchMethodException e)
            {
            }
            return null;
          }

总结:为每个case都指定了tester,就是每个case都有对应的负责人,到时候出错了好找人啊。

其实还有很多其他的应用,大家可以想下

原文地址:https://www.cnblogs.com/season-xie/p/6337683.html