一起买beta版UI测试
测试目的
保证代码质量,对各个单元进行测试,可以有效地保证代码的可靠性,让模块在与别的模块整合时出现更少的错误。
UI测试
- 登录模块测试
登录模拟过程。
- 发帖模块测试
发帖模拟过程
测试过程
- 登录模块测试
package com.example.s.buytogether;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.example.s.buytogether.login.Login;
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.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginTest {
private static final String STRING_TO_BE_TYPED = "b";
@Rule
public ActivityTestRule<Login> mActivityRule = new ActivityTestRule<>(
Login.class);
@Test
public void login() {
onView(withId(R.id.edtTxt_userName)).perform(typeText("b"));
onView(withId(R.id.edtTxt_userPassword)).perform(typeText("b"));
onView(withId(R.id.btn_login)).perform(click());
}
}
测试结果:
- 发帖模块测试
package com.example.s.buytogether;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.example.s.buytogether.newPosts.NewPosts;
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.scrollTo;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
@LargeTest
public class NewPostsTest {
@Rule
public ActivityTestRule<NewPosts> mActivityRule = new ActivityTestRule<>(
NewPosts.class);
@Test
public void login() {
onView(withId(R.id.edtTxt_description)).perform(scrollTo(), typeText("yaobuyaolaiwana~~~"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_location)).perform(scrollTo(), typeText("30#417"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_phone)).perform(scrollTo(), typeText("110"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_indateTimeDay)).perform(scrollTo(), typeText("30"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_indateTimeHour)).perform(scrollTo(), typeText("2"), closeSoftKeyboard());
// onView(withId(R.id.edtTxt_moreDescription)).perform(scrollTo(), typeText("hahahahhaha"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_price)).perform(scrollTo(), typeText("30"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_unit)).perform(scrollTo(), typeText("po"), closeSoftKeyboard());
onView(withId(R.id.edtTxt_menCount)).perform(scrollTo(), typeText("2"), closeSoftKeyboard());
// onView(withId(R.id.img_addPosts)).perform(click());
}
}
测试结果:
结果统计
共计两个测试,两个均无问题
质量评估
所测试模块,均可正常通过
测试总结
由于时间原因,只做了两个部分的UI测试,其他部分依然还是存在一系列的bug正在解决中。但是也感觉espresso这个UI自动化测试的厉害之处,避免了人工手动的复杂输入,操作起来很炫酷。