SlideShare a Scribd company logo
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
onView(withID(R.id.refID1)).perform(Click());
onView(withID(R.id.refID3)).perform(typeText("InputText"));
onView(withID(R.id.refID4)).perform(typeText("Input Text2"),closeSoftKeyboard());
onView(withId(R.id.resultText))
.check(matches(withText(("AsserstionTesttoMatch fromUI"))));
}
}
Step4:
Right clickonTest methodandClickon "Run<testMethod>"inEmulatoror Real Device.
Step5: [Optional] Creationof TestSuite formultiple classes
To Create TestSuite formultiple Testclasses(xxTest.java) filesunderandroidTestpackage
Create a class undersame androidTestpackage withclassname as"UnitTestSuite".
importcom.example.android.testing.mysample.DemoClassTest;
importcom.example.android.testing.mysample.DemoClassTest;
importorg.junit.runner.RunWith;
importorg.junit.runners.Suite;
// Runsall unittests.
@RunWith(Suite.class)
@Suite.SuiteClasses({DemoClassTest.class,
CalculatorAddParameterizedTest.class})
publicclassUnitTestSuite {}
AndRun yourTest Suite fromthisclass.Welcome toEspresso!!
Ref Note:
Gradle Info:
applyplugin:'com.android.application'
android{
compileSdkVersion25
buildToolsVersion"25.0.2"
defaultConfig{
applicationId"com.example.ui.espresso"
minSdkVersion15
targetSdkVersion25
versionCode 1
versionName "1.0"
//Addedinstrumentationrunnerforconfiguration-----------------------------------
testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes{
release {
minifyEnabledfalse
proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies{
compile fileTree(dir:'libs',include:['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group:'com.android.support',module:'support-annotations'
})
// Espressodependencies----------------------------
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2'){
exclude group:'com.android.support',module:'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.5'){
exclude group:'com.android.support',module:'support-annotations'
}
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile'junit:junit:4.12'
}
Ref URL:
https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html#run
You can alsouser EspressoRecorderinAndroidStudiotowrite the testcases.
----- CommentsandSuggestionsare welcome.Love totake yourquestions!Thanks ----

More Related Content

What's hot (20)

PPTX
Testing Android Application, Droidcon Torino
Pietro Alberto Rossi
 
PPTX
Android testing
JinaTm
 
PDF
Using eggplant - Overview
Su tol
 
PDF
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
DicodingEvent
 
DOC
Sample - Test Cases - Adobe Flash
Bob Powers
 
PDF
Testing Native Apps at PAYBACK
Marcel Gehlen
 
PDF
Appium@Work at PAYBACK
Marcel Gehlen
 
PDF
Android Test Automation Workshop
Eduardo Carrara de Araujo
 
PDF
Utilizando Espresso e UIAutomator no Teste de Apps Android
Eduardo Carrara de Araujo
 
PPTX
Appium overview
Abhishek Yadav
 
PDF
Groovy Testing Aug2009
guest4a266c
 
PDF
Distributing Python Application the right way
Vaibhav Mishra
 
PPTX
Developing Android Apps
Claire Lee
 
DOCX
Daniel Neumann Project Experience
Daniel Neumann, PhD
 
PDF
Using PhoneGap Command Line
Anuchit Chalothorn
 
PDF
CookpadTechConf2018-(Mobile)TestAutomation
Kazuaki Matsuo
 
PDF
Automated UI Testing Frameworks
TestObject - Mobile Testing
 
PPTX
Automation testing on ios platform using appium
Ambreen Khan
 
PDF
MonkeyTalk Documentation
Vivek Pansara
 
PDF
Game now
matero22
 
Testing Android Application, Droidcon Torino
Pietro Alberto Rossi
 
Android testing
JinaTm
 
Using eggplant - Overview
Su tol
 
Dicoding Developer Coaching #13: Android | Melakukan Testing secara Otomatis ...
DicodingEvent
 
Sample - Test Cases - Adobe Flash
Bob Powers
 
Testing Native Apps at PAYBACK
Marcel Gehlen
 
Appium@Work at PAYBACK
Marcel Gehlen
 
Android Test Automation Workshop
Eduardo Carrara de Araujo
 
Utilizando Espresso e UIAutomator no Teste de Apps Android
Eduardo Carrara de Araujo
 
Appium overview
Abhishek Yadav
 
Groovy Testing Aug2009
guest4a266c
 
Distributing Python Application the right way
Vaibhav Mishra
 
Developing Android Apps
Claire Lee
 
Daniel Neumann Project Experience
Daniel Neumann, PhD
 
Using PhoneGap Command Line
Anuchit Chalothorn
 
CookpadTechConf2018-(Mobile)TestAutomation
Kazuaki Matsuo
 
Automated UI Testing Frameworks
TestObject - Mobile Testing
 
Automation testing on ios platform using appium
Ambreen Khan
 
MonkeyTalk Documentation
Vivek Pansara
 
Game now
matero22
 

Similar to 5 Easy Steps to Learn Espresso (10)

PDF
A Comprehensive Guide To Espresso Testing.pdf
flufftailshop
 
PDF
Overview the Challenges and Limitations of Android App Automation with Espres...
Sauce Labs
 
PDF
Espresso testing
vodqancr
 
PPTX
Do You Enjoy Espresso in Android App Testing?
Bitbar
 
PPTX
Espresso workshop
Ketan Soni
 
PDF
Android UI Testing with Espresso
Gary Cheng
 
PDF
Espresso devoxx 2014
Publicis Sapient Engineering
 
PDF
Ui testing with espresso
Droidcon Spain
 
PDF
Espresso Barista
Shauvik Roy Choudhary, Ph.D.
 
PPTX
Instrumentation testing
Christiane Morais Silva
 
A Comprehensive Guide To Espresso Testing.pdf
flufftailshop
 
Overview the Challenges and Limitations of Android App Automation with Espres...
Sauce Labs
 
Espresso testing
vodqancr
 
Do You Enjoy Espresso in Android App Testing?
Bitbar
 
Espresso workshop
Ketan Soni
 
Android UI Testing with Espresso
Gary Cheng
 
Espresso devoxx 2014
Publicis Sapient Engineering
 
Ui testing with espresso
Droidcon Spain
 
Instrumentation testing
Christiane Morais Silva
 
Ad

Recently uploaded (20)

PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Ad

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
  • 2. onView(withID(R.id.refID1)).perform(Click()); onView(withID(R.id.refID3)).perform(typeText("InputText")); onView(withID(R.id.refID4)).perform(typeText("Input Text2"),closeSoftKeyboard()); onView(withId(R.id.resultText)) .check(matches(withText(("AsserstionTesttoMatch fromUI")))); } } Step4: Right clickonTest methodandClickon "Run<testMethod>"inEmulatoror Real Device. Step5: [Optional] Creationof TestSuite formultiple classes To Create TestSuite formultiple Testclasses(xxTest.java) filesunderandroidTestpackage Create a class undersame androidTestpackage withclassname as"UnitTestSuite". importcom.example.android.testing.mysample.DemoClassTest; importcom.example.android.testing.mysample.DemoClassTest; importorg.junit.runner.RunWith; importorg.junit.runners.Suite; // Runsall unittests. @RunWith(Suite.class) @Suite.SuiteClasses({DemoClassTest.class, CalculatorAddParameterizedTest.class}) publicclassUnitTestSuite {} AndRun yourTest Suite fromthisclass.Welcome toEspresso!! Ref Note: Gradle Info: applyplugin:'com.android.application' android{ compileSdkVersion25 buildToolsVersion"25.0.2" defaultConfig{ applicationId"com.example.ui.espresso" minSdkVersion15 targetSdkVersion25 versionCode 1
  • 3. versionName "1.0" //Addedinstrumentationrunnerforconfiguration----------------------------------- testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner" } buildTypes{ release { minifyEnabledfalse proguardFilesgetDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } } dependencies{ compile fileTree(dir:'libs',include:['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',{ exclude group:'com.android.support',module:'support-annotations' }) // Espressodependencies---------------------------- androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2'){ exclude group:'com.android.support',module:'support-annotations' } androidTestCompile('com.android.support.test:runner:0.5'){ exclude group:'com.android.support',module:'support-annotations' } compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.android.support:design:25.3.1' testCompile'junit:junit:4.12' } Ref URL: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html#run You can alsouser EspressoRecorderinAndroidStudiotowrite the testcases. ----- CommentsandSuggestionsare welcome.Love totake yourquestions!Thanks ----