Espresso is a testing framework for Android to make it easy to write reliable user interface tests.
Google released the Espresso framework in Oct. 2013. Since its 2.0 release Espresso is part of the Android Support Repository.
Espresso automatically synchronizes your test actions with the user interface of your application. The framework also ensures that your activity is started before the tests run. It also let the test wait until all observed background activities have finished.
1 of 3
Download to read offline
More Related Content
5 Easy Steps to Learn Espresso
1. 5 Easy Steps to Learn Espresso
Step1. Pre RequisitesforSetup
1. AndroidStudioshouldbe installed
2. Create a EmulatorinAndroidStudioorConnectreal device toruna TestScript.
3. Sample Appshouldbe importedorcode writtenfora DemoProject& can run app successfully.
(If youare not goodat androidbasicsin developmentthenrecommended touse demoprojectapp
of AndroidStudio)
4. Turn of DeveloperSettings ->Turn Off all animations indevice.
Step2: Crate Test Package under targetedProject Directory/App
Go to navigate optioninAndroidStudioandClickonTestoptiontocreate a TestClass.
(UnderApp -> Java -> AndroidTestPackage)
Step3: Sample TestCase Program
OpenyourTestCaseTest.javafileandwrite code asbelow:
//RequiredPackagesforEspresso
importstaticandroid.support.test.espresso.Espresso.onView;
importstaticandroid.support.test.espresso.matcher.ViewMatchers.withText;
importstaticandroid.support.test.espresso.matcher.RootMatchers.withDecorView;
importstaticandroid.support.test.espresso.assertion.ViewAssertions.matches;
@RunWith(AndroidJUnit4.class)
publicclassDemoClassTest{
@Rule
ActivityTestRule<AppActivityClassName>ref var=
new ActivityTestRule<>(AppActivityClass.class);
/**
Ref Code onlyandwrite as per yourapp UI attribute
**/
@Test
publicvoidtestcase1(){
ViewInteractionref =onView(withID(R.id.refID1));
ref.perform(click());
onView(withId(R.id.resultText))
.check(matches(withText(("AsserstionTesttoMatch fromUI"))));
//OR