旅图——UI测试

测试目标

  • 保证代码质量,确保基础功能的实现,可以有效地保证代码的可靠性,让模块在与别的模块整合时出现更少的错误,减少最终测试时查找困难无方向。

UI测试

登录过程

  • 模拟登录过程,密码正确与密码错误的情况

测试代码

package com.example.asdf.test;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class loginTest {
@Rule
public ActivityTestRule<login> mActivityRule = new ActivityTestRule<>(
        login.class);
@Test
public void sayHello(){
    onView(withId(R.id.account)).perform(typeText("1234567890"), closeSoftKeyboard());
    onView(withId(R.id.password)).perform(typeText("1234567890"),closeSoftKeyboard());
    onView(withId(R.id.login)).perform(click());
}
} 

测试结果

密码错误

密码正确

用户信息修改

  • 模拟用户信息修改过程,修改成功

测试代码

public class modifyInformation {


@Rule
public ActivityTestRule<modifyinformation> mActivityRule = new ActivityTestRule<>(
        modifyinformation.class);

@Test
public void modify(){
    onView(withId(R.id.newusername)).perform(typeText("fire"), closeSoftKeyboard());
    onView(withId(R.id.newintroduce)).perform(typeText("233"),closeSoftKeyboard());
    onView(withId(R.id.newsubmit)).perform(click());
}
}

测试结果

测试总结

  • 测试通过。由于app含有涉及到从服务器获取图片信息的功能模块与获取验证码功能,无法通过espresso进行UI自动化测试,只能进行登录过程测试展示。
posted @ 2016-12-22 21:12  606notconnected  阅读(175)  评论(2编辑  收藏  举报