robotium自动化测试(简单黑盒)

黑盒测试

1.配置Gradle

robotium gradle 配置.png

2.在src目录下新建androidTest文件夹,在建一个名为java的文件夹,然后新建一个类ApplicationTest,这个类继承ActivityInstrumentationTestCase2<启动页类>
3,贴上具体代码

public class ApplicationTest extends ActivityInstrumentationTestCase2{

   public ApplicationTest() {
       super(SplashActivity.class);
   }
   private Solo solo;

   /**
    * 在测试开始之前运行  产生Solo对象
    */
   @Override
   public void setUp() throws Exception {
       solo = new Solo(getInstrumentation());
       getActivity();
   }

   /**
    * 测试结束后关闭test中打开的activities
    */
   @Override
   public void tearDown() throws Exception {
       solo.finishOpenedActivities();
   }

   /**
    * 测试
    */
   public void testButtonClick() throws Exception {
       //锁屏
       solo.unlockScreen();

       for (int i=0; i< 10;i++){
           solo.clickOnText("直播预告");
           solo.sleep(500);
           solo.clickOnText("我的课表");
           solo.sleep(500);
           solo.clickOnText("个人中心");
           solo.sleep(500);
           solo.clickOnText("首页");
           solo.sleep(500);
           //点击全部课程
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.rl_course_all));
           //模拟请求时间 或手指停留时间
           solo.sleep(500);
           solo.clickOnText("呼吸内科");
           solo.sleep(500);
           solo.clickOnText("心血管内科");
           solo.sleep(500);
           solo.clickOnText("全部学科");
           solo.sleep(500);
           //点击列表
           solo.clickInRecyclerView(2);
           solo.sleep(1000);
           solo.clickOnText("课程描述");
           solo.sleep(500);
           solo.clickOnText("课程评价");
           solo.sleep(500);
           solo.clickOnText("课程目录");
           solo.sleep(500);
           solo.goBack();

           solo.clickOnText("呼吸内科");
           solo.sleep(500);
           solo.drag(0,0,1000,500,1);
           solo.sleep(1000);
           solo.drag(0,0,500,1000,1);
           solo.sleep(1000);
           solo.goBack();
           solo.sleep(500);
           solo.clickOnText("个人中心");
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.rl_account));
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.personal_home_image_fl));
           solo.clickOnText("取消");
           solo.sleep(500);
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.personal_home_name_tv));
           solo.sleep(1000);
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.personal_name_et));
           solo.enterText(0, "自动化测试写名字");
           solo.sleep(1000);
           solo.clickOnText("完成");
           solo.sleep(500);
           solo.goBack();
           solo.clickOnText("我的学院");
           solo.sleep(500);
           solo.clickOnText("进入学院");
           solo.sleep(500);
           solo.clickOnText("专家");
           solo.sleep(500);
           solo.clickOnText("简介");
           solo.sleep(500);
           solo.goBack();
           solo.goBack();
           solo.clickOnText("设置中心");
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.switch_wifi));
           solo.sleep(500);
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.switch_wifi));
           solo.sleep(500);
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.ll_definition));
           solo.sleep(500);
           solo.goBack();
           solo.clickOnView(solo.getView(com.senyint.edu.college.stu.R.id.ll_version));
           solo.sleep(1500);
           solo.clickOnText("退出登录");
           solo.clickOnText("取消");
           solo.goBack();
           solo.goBack();
           solo.clickOnText("取消");
           solo.clickOnText("首页");

       }
       assertTrue(true);
   }
}

你可能感兴趣的:(robotium自动化测试(简单黑盒))