• uiautomator 自定义testrunner使用和启动原理


    继承testrunner实现runner

    public class TestRunner extends UiAutomatorTestRunner
    {
        private final List<String> mTestClasses = new ArrayList<String>();
     
        @Override
        public void run(List<String> testClasses, Bundle params, boolean debug, boolean monkey)
        {
            try
            {
                testClasses.removeAll(testClasses);  //removeAll
                addTestClasses();
                testClasses.addAll(mTestClasses); //addAll
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            super.run(testClasses, params, debug, monkey);
    }

    运行testrunner

    -e runner com.meizu.browser.test.TestRunner

    应用

    可以根据外部传入的值,来确定需要执行什么用例

    例如-e priority p1  取出priority值,在addtestcase的时候只加入priority是P1的testcase

    获取runner源码

    /*     */   protected UiAutomatorTestRunner getRunner() {
    /* 140 */     if (this.mRunner != null) {
    /* 141 */       return this.mRunner;
    /*     */     }
    /*     */     
    /* 144 */     if (this.mRunnerClassName == null) {
    /* 145 */       this.mRunner = new UiAutomatorTestRunner();
    /* 146 */       return this.mRunner;
    /*     */     }
    /*     */     
    /* 149 */     Object o = null;
    /*     */     try {
    /* 151 */       Class<?> clazz = Class.forName(this.mRunnerClassName);
    /* 152 */       o = clazz.newInstance();
    /*     */     } catch (ClassNotFoundException cnfe) {
    /* 154 */       System.err.println("Cannot find runner: " + this.mRunnerClassName);
    /* 155 */       System.exit(-4);
    /*     */     } catch (InstantiationException ie) {
    /* 157 */       System.err.println("Cannot instantiate runner: " + this.mRunnerClassName);
    /* 158 */       System.exit(-4);
    /*     */     } catch (IllegalAccessException iae) {
    /* 160 */       System.err.println("Constructor of runner " + this.mRunnerClassName + " is not accessibile");
    /* 161 */       System.exit(-4);
    /*     */     }
    /*     */     try {
    /* 164 */       UiAutomatorTestRunner runner = (UiAutomatorTestRunner)o;
    /* 165 */       this.mRunner = runner;
    /* 166 */       return runner;
    /*     */     } catch (ClassCastException cce) {
    /* 168 */       System.err.println("Specified runner is not subclass of " + UiAutomatorTestRunner.class.getSimpleName());
    /*     */       
    /* 170 */       System.exit(-4);
    /*     */     }
    /*     */     
    /* 173 */     return null;
    /*     */   }
  • 相关阅读:
    乘法DAC一点知识
    #4 判断字符串是否为整数
    #3 不使用循环输出1到100
    #2 判断一个字符串是否包含重复字符
    #22 结语
    #1 组成互不相同且不重复的三位数
    #21 Python异常
    #19 re&jieba模块
    2020国庆正睿笔记
    2019正睿csp-s赛前冲刺
  • 原文地址:https://www.cnblogs.com/season-xie/p/6337682.html
Copyright © 2020-2023  润新知