网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
CloudDisk示例
对于我们这个浓缩版的CloudDisk,界面上也比较简单。主要是有一个主界面,主界面上主要为文件、动态、用户。(后续的MV*重构篇会持续补充页面交互及逻辑)
我们可以设计一组UI的测试验证基本的功能。主要的几个测试点如下:
- 主界面能正常运行并显示3个Fragment
- 3个Fragment能正常显示
- 点击登录按钮,能够跳转到登录页面
测试设计的用例如下:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class SmokeTesting {
@Test
public void should_show_fragment_list_when_activity_launch() {
//given
ActivityScenario scenario = ActivityScenario.launch(MainActivity.class);
scenario.onActivity(activity -> {
//when
onView(withText(R.string.tab_user)).perform(click());
//then
List fragments = activity.getSupportFragmentManager().getFragments();
assertThat(fragments.size() == 3);
assertThat(fragments.get(0) instanceof FileFragment);
assertThat(fragments.get(1) instanceof DynamicFragment);
assertThat(fragments.get(2) instanceof UserCenterFragment);
});
}
@Test
public void show_show_file_ui_when_click_tab_file() {
//given
ActivityScenario scenario = ActivityScenario.launch(MainActivity.class);
scenario.onActivity(activity -> {
//when
onView(withText(R.string.tab_file)).perform(click());
//then
onView(withText(“Hello file fragment”)).check(matches(isDisplayed()));
});
}
@Test
public void show_show_dynamic_ui_when_click_tab_dynamic() {
//given
ActivityScenario scenario = ActivityScenario.launch(MainActivity.class);
scenario.onActivity(activity -> {
//when
onView(withText(R.string.tab_dynamic)).perform(click());
//then
onView(withText(“Hello dynamic fragment”)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
});
}
@Test
public void show_show_user_center_ui_when_click_tab_dynamic() {
//given
ActivityScenario scenario = ActivityScenario.launch(MainActivity.class);
scenario.onActivity(activity -> {
//when
onView(withText(R.string.tab_user)).perform(click());
//then
onView(withText(“Hello user center fragment”)).check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
});
}
@Test
public void show_show_login_ui_when_click_login_button() {
//given
ActivityScenario scenario = ActivityScenario.launch(MainActivity.class);
scenario.onActivity(activity -> {
Intents.init();
//when
onView(withId(R.id.fab)).perform(click());
//then
intended(IntentMatchers.hasComponent(“com.cloud.disk.platform.login.LoginActivity”));
Intents.release();
});
}
}
详细代码见Github提交
我们可以将用例运行在Robolectric上,提高反馈的速度,执行命令如下:
./gradlew testDebug --tests SmokeTesting
测试执行结果如下:
当然实际的项目里情况更复杂,数据可能来自网络服务、数据库等等。我们还需要进行Mock。后续的MV*重构篇会持续补充常见坏味道示例代码及更多的自动化测试用例。
更多测试框架及设计可以参考Google官方 在 Android 平台上测试应用
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**