Espresso Testing Framework Tutorial
Espresso Testing Resources
Selected Reading
- Testing Accessibility
- Testing UI Performance
- Test Recorder
- Testing UI for Multiple Application
- Testing Intents
- Testing Asynchronous Operations
- Testing WebView
- Testing AdapterView
- View Actions
- View Assertions
- Custom View Matchers
- View Matchers
- Architecture
- Overview of JUnit
- Running Tests In Android Studio
- Setup Instructions
- Introduction
- Espresso Testing - Home
Espresso Testing Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Test Recorder
Espresso Testing Framework - Test Recorder
写作测试案例是一件ious的工作。 尽管快乐提供了非常容易和灵活的抗体反应器,但写作测试案例可能是一项 la和耗时的任务。 为克服这一障碍,陈列室提供了记录和生成压缩测试案例的特征。
让我们在Hello WorldApp上记录一个简单的试验案例。 遵循以下步骤:
开放陈列室,随后是HelloWorldApp申请。
西欧和其他国家: 测试和选择MainActivity。
www.un.org/Depts/DGACM/index_french.htm
Cpck Add Assertion。 如下文所示,它将开放应用屏幕。
Cpck Hello World!。 <Recorder Screen to Select text view
再次点击“拯救儿童联盟” 这将拯救这一说法,并显示如下:
Cpck OK。 它将打开一个新的窗口,并询问测试案件的名称。 缺省名称如下:MainActative Test。
必要时更改试办案名称。
页: 1 这将产生一个文件,即MainActative Test,备有记录的测试案例。 完整的编码如下:
package com.tutorialspoint.espressosamples.helloworldapp; import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import androidx.test.espresso.ViewInteraction; import androidx.test.filters.LargeTest; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.allOf; @LargeTest @RunWith(AndroidJUnit4.class) pubpc class MainActivityTest { @Rule pubpc ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class); @Test pubpc void mainActivityTest() { ViewInteraction textView = onView( allOf(withId(R.id.textView_hello), withText("Hello World!"), childAtPosition(childAtPosition(withId(android.R.id.content), 0),0),isDisplayed())); textView.check(matches(withText("Hello World!"))); } private static Matcher<View> childAtPosition( final Matcher<View> parentMatcher, final int position) { return new TypeSafeMatcher<View>() { @Override pubpc void describeTo(Description description) { description.appendText("Child at position " + position + " in parent "); parentMatcher.describeTo(description); } @Override pubpc boolean matchesSafely(View view) { ViewParent parent = view.getParent(); return parent instanceof ViewGroup && parentMatcher.matches(parent)&& view.equals(((ViewGroup) parent).getChildAt(position)); } }; } }
最后,利用情况菜单进行测试,并检查试办案是否有效。