SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
Test Android Application with Robotium:
1. Create Test Project
To test an Android application using Robotium, we need to create a test project within the package
(com.calculator) of Simple Calculator Project Source Code.
Put project name
Select test target or AUT(application under test)
Select Min SDK version
We will move on to design our logic to test AndroidCaculator. We need to create test case class where we will                                       
write code to test AndroidCalculator's main class (Main.java).
2. Create Test Case
In test project from project explorer window right click on com.calculator.test select New then others. On                             
New window expand Java and then expand Junit category and select Junit Test Case and click on Next.
On New Junit Test Case screen, most of the options will be automatically filled as we have already created
test project (AndroidCalculatorTest) with project (AndroidCalculator). We need to enter the Name of Test
case, which I will enter TestMain, as I am going to test (main.java) of AndroidCalculator project. On next
section check Setup(), tearDown() & Constructor options and click on Finish.
A new test case by the name of TestMain will be created into com.calculator.test package of my test project
(AndroidCaculatorTest)
3. Add Robotium jar
We need to reference the Robotium jar to our project.
Right click on project select Build Path, and then click on Configure Build Path option. On Properties
window click on Libraries tab and add Robotium latest jar into project. we can download Robotium jar from
http://code.google.com/p/robotium/downloads/list
Note: In the latest Android SDK versions(17 or above) a java.lang.NoClassDefFoundError:
com.jayway.android.robotium.solo.Solo error is shown if the Robotium jar is not exported . To fix the
issue, after adding the Robotium jar go to the "Order & Export" tab and click the check­box besides the
Robotium Jar and then click "OK". Please see the screenshot below.
4. Write Test Case code
In our create test case we will access the contents of AndroidCalculator and do followings,
1. Call/Access first & second input controls (EditFields)
2. Enter values of our own choice
3. Access & Click on Multiply button
4. Put assert to verify their multiplication result into result field. And add
following code into TestMain.java  class and save it.
packagecom.calculator.test;
importandroid.test.ActivityInstrumentationTestCase2;
importandroid.widget.EditText;
importandroid.widget.TextView;
importcom.calculator.Main;
importcom.calculator.R;
importcom.jayway.android.robotium.solo.Solo;
publicclassTestMainextendsActivityInstrumentationTestCase2<Main>{
privateSolosolo;
publicTestMain(){
super(Main.class);
}
@Override
protectedvoidsetUp()throwsException{
super.setUp();
solo=newSolo(getInstrumentation(),getActivity());
}
publicvoidtestDisplayBlackBox(){
//Enter10infirstedit-field
solo.enterText(0,"10");
//Enter20infirstedit-field
solo.enterText(1,"20");
//ClickonMultiplybutton
solo.clickOnButton("Multiply");
//Verifythatresultantof10x20
assertTrue(solo.searchText("200"));
}
publicvoidtestDisplayWhiteBox(){
//Definingourownvaluestomultiply
floatfirstNumber=10;
floatsecondNumber=20;
floatresutl=firstNumber*secondNumber;
//AccessFirstvalue(edit-filed)andputtingfirstNumbervalueinit
EditTextFirsteditText=(EditText)solo.getView(R.id.EditText01);
solo.enterText(FirsteditText,String.valueOf(firstNumber));
//AccessSecondvalue(edit-filed)andputtingSecondNumbervalueinit
EditTextSecondeditText=(EditText)solo.getView(R.id.EditText02);
solo.enterText(SecondeditText,String.valueOf(secondNumber));
//ClickonMultiplybutton
solo.clickOnButton("Multiply");
assertTrue(solo.searchText(String.valueOf(resutl)));
TextViewoutputField=(TextView)solo.getView(R.id.TextView01);
//Asserttoverifyresultwithvisiblevalue
assertEquals(String.valueOf(resutl),outputField.getText().toString());
}
@Override
protectedvoidtearDown()throwsException{
solo.finishOpenedActivities();
}
}
5. Run Test Case
Now as we are almost done so now its time to run our test case.
Right click on TestMain.java file select Run As option and then click on Android Junit Test. It will start
running Junit test.
Select the emulator or device to run the test (we will be using Android default emulator) , and wait for a while
to see the magic of Robotium.
If things are going fine
1.  Emulator will load, Unlock it.
2. AndroidCalculator application will load
3.  It will automatically enter first & second values in First and Second EditField, and click on
Multiply button (you can see all this happening as record & play scripts)
4.  After successfully execution it will show green bar showing the successful execution and all results
are passed.

Contenu connexe

Tendances

Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
Deepa Rani
 
Diving into VS 2015 Day4
Diving into VS 2015 Day4Diving into VS 2015 Day4
Diving into VS 2015 Day4
Akhil Mittal
 
Diving into VS 2015 Day2
Diving into VS 2015 Day2Diving into VS 2015 Day2
Diving into VS 2015 Day2
Akhil Mittal
 
Diving into VS 2015 Day3
Diving into VS 2015 Day3Diving into VS 2015 Day3
Diving into VS 2015 Day3
Akhil Mittal
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1
Akhil Mittal
 

Tendances (20)

Coded ui test
Coded ui testCoded ui test
Coded ui test
 
Android styles and themes
Android   styles and themesAndroid   styles and themes
Android styles and themes
 
Coded ui - lesson 2 - coded ui test builder
Coded ui - lesson 2 - coded ui test builderCoded ui - lesson 2 - coded ui test builder
Coded ui - lesson 2 - coded ui test builder
 
Android Training Ahmedabad , Android Project Training Ahmedabad, Android Live...
Android Training Ahmedabad , Android Project Training Ahmedabad, Android Live...Android Training Ahmedabad , Android Project Training Ahmedabad, Android Live...
Android Training Ahmedabad , Android Project Training Ahmedabad, Android Live...
 
Android software development – the first few hours
Android software development – the first few hoursAndroid software development – the first few hours
Android software development – the first few hours
 
Training android
Training androidTraining android
Training android
 
Diving into VS 2015 Day4
Diving into VS 2015 Day4Diving into VS 2015 Day4
Diving into VS 2015 Day4
 
Android development module
Android development moduleAndroid development module
Android development module
 
Diving into VS 2015 Day2
Diving into VS 2015 Day2Diving into VS 2015 Day2
Diving into VS 2015 Day2
 
Coded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui testCoded ui - lesson 4 - coded ui test
Coded ui - lesson 4 - coded ui test
 
Utilizando expresso uiautomator na automacao de testes em apps android
Utilizando expresso uiautomator na automacao de testes em apps androidUtilizando expresso uiautomator na automacao de testes em apps android
Utilizando expresso uiautomator na automacao de testes em apps android
 
Advanced Coded UI Testing
Advanced Coded UI TestingAdvanced Coded UI Testing
Advanced Coded UI Testing
 
Lab 2: Creating and applying tags
Lab 2: Creating and applying tagsLab 2: Creating and applying tags
Lab 2: Creating and applying tags
 
Robotium - sampath
Robotium - sampathRobotium - sampath
Robotium - sampath
 
Diving into VS 2015 Day3
Diving into VS 2015 Day3Diving into VS 2015 Day3
Diving into VS 2015 Day3
 
Coded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object ModelCoded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object Model
 
Android course (lecture1)
Android course (lecture1)Android course (lecture1)
Android course (lecture1)
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1
 
Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)Module 2: C# 3.0 Language Enhancements (Material)
Module 2: C# 3.0 Language Enhancements (Material)
 
UI testing frameworks and the Coded UI testing paradigm
UI testing frameworks and the Coded UI testing paradigm UI testing frameworks and the Coded UI testing paradigm
UI testing frameworks and the Coded UI testing paradigm
 

Similaire à Android calculatortest

MPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_DocumentationMPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_Documentation
Xin Shao
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
llmeade
 

Similaire à Android calculatortest (20)

MPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_DocumentationMPointInc_AndroidSDK_Documentation
MPointInc_AndroidSDK_Documentation
 
Unit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdfUnit Testing Using Mockito in Android (1).pdf
Unit Testing Using Mockito in Android (1).pdf
 
Publishing and delivery of mobile application
Publishing and delivery of mobile applicationPublishing and delivery of mobile application
Publishing and delivery of mobile application
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
Coded ui - lesson 1 - overview
Coded ui - lesson 1 - overviewCoded ui - lesson 1 - overview
Coded ui - lesson 1 - overview
 
Mobile Worshop Lab guide
Mobile Worshop Lab guideMobile Worshop Lab guide
Mobile Worshop Lab guide
 
Android Programing Course Material Labs
Android Programing Course Material LabsAndroid Programing Course Material Labs
Android Programing Course Material Labs
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon Studio
 
Hello android example.
Hello android example.Hello android example.
Hello android example.
 
Final NEWS.pdf
Final NEWS.pdfFinal NEWS.pdf
Final NEWS.pdf
 
Final NewsApp.pdf
Final NewsApp.pdfFinal NewsApp.pdf
Final NewsApp.pdf
 
Tang doanh thu quang cao di dong
Tang doanh thu quang cao di dongTang doanh thu quang cao di dong
Tang doanh thu quang cao di dong
 
Testing Android applications with Maveryx
Testing Android applications with MaveryxTesting Android applications with Maveryx
Testing Android applications with Maveryx
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Introduction to Android and Java.pptx
Introduction to Android and Java.pptxIntroduction to Android and Java.pptx
Introduction to Android and Java.pptx
 
Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008Steps how to create active x using visual studio 2008
Steps how to create active x using visual studio 2008
 
Hacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdfHacking the Codename One Source Code - Part IV - Transcript.pdf
Hacking the Codename One Source Code - Part IV - Transcript.pdf
 
Build Your First Android App
Build Your First Android AppBuild Your First Android App
Build Your First Android App
 
The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185The Ring programming language version 1.5.4 book - Part 71 of 185
The Ring programming language version 1.5.4 book - Part 71 of 185
 

Dernier

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Android calculatortest