Robotium 用例分组运行

Robotium是开源的Android界面自动化测试的框架,它内部集成了junit,以test开头的方法,会自动识别成测试用例,这样做带来快捷的同时,却也带来了不便。如果我们要分功能、分模块等,Robotium不支持自定义的testsuite。在这里我们可以用adb shell am instrument这条命令来实现分组。

  • 不分组,全部运行
      adb shell am instrument -w com.example.test/android.test.InstrumentationTestRunner
    
  • 以类进行分组
      adb shell am instrument -w -e class  com.example.test.testA com.example.test/android.test.InstrumentationTestRunner  
    
  • 以方法进行分组
      adb shell am instrument -w -e class com.huawei.mao.test.testA\#testadd4 com.huawei.mao.test/android.test.InstrumentationTestRunner
    
  • 以注释分组

    我们可以使用自己的注释接口,为我们的测试case分类。

    声明注释接口:

      @Target({ElementType.METHOD, ElementType.TYPE})
      @Retention(RetentionPolicy.RUNTIME)
      @Documented
      public @interface CatagoryGroup {
      }
    

    在测试case中使用注释:

      @CatagoryGroup
      public void testSearchWhileTabSwitch()
      {
      ...
      }
    

    运行命令:

      adb shell am instrument -w -e annotation com.yeetrack.CatagoryGroup com.example.test/android.test.InstrumentationTestRunner
    

xml运行结果

robotium默认的的是android.test.InstrumentationTestRunner,这个runner不提供xml结果,我们可以使用com.zutubi.android.junitreport.JUnitReportTestRunner,这个runner,case运行结束后,会把junit的xml结果保存在手机的/data/data/someapk/files/Junit-report.xml中。

版权声明

本站文章、图片、视频等(除转载外),均采用知识共享署名 4.0 国际许可协议(CC BY-NC-SA 4.0),转载请注明出处、非商业性使用、并且以相同协议共享。

© 空空博客,本文链接:https://www.yeetrack.com/?p=1035