SlideShare a Scribd company logo
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.

More Related Content

PPTX
Coded ui - lesson 3 - case study - calculator
PPTX
Android course (lecture2)
PPT
Getting started with android studio
PPTX
Android studio installation
PPT
Day 4: Android: UI Widgets
PPTX
Android studio installation
PPTX
Android the first app - hello world - copy
PPTX
Unit testing with visual studio 2012
Coded ui - lesson 3 - case study - calculator
Android course (lecture2)
Getting started with android studio
Android studio installation
Day 4: Android: UI Widgets
Android studio installation
Android the first app - hello world - copy
Unit testing with visual studio 2012

What's hot (20)

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

Similar to Android calculatortest (16)

PDF
Introduction to Robotium
PDF
Android Automation Using Robotium
PDF
Robotium at Android Only 2010-09-29
PPTX
Robotium
PDF
Robotium Tutorial
PDF
Android unittesting
PDF
Rockstar Android Testing (Mobile TechCon Munich 2014)
PDF
Testing on Android
DOCX
AppiumSetupConfigurationonWindows
PPT
Test Automation On Android Platform Using Robotium
PDF
Hitchhiker's guide to Functional Testing
DOCX
UIAutomator
PDF
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
PPTX
Lecture 9 testing_packaging_app
PPT
PPTX
Lecture 9 testing_packaging_app
Introduction to Robotium
Android Automation Using Robotium
Robotium at Android Only 2010-09-29
Robotium
Robotium Tutorial
Android unittesting
Rockstar Android Testing (Mobile TechCon Munich 2014)
Testing on Android
AppiumSetupConfigurationonWindows
Test Automation On Android Platform Using Robotium
Hitchhiker's guide to Functional Testing
UIAutomator
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Lecture 9 testing_packaging_app
Lecture 9 testing_packaging_app
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Electronic commerce courselecture one. Pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
NewMind AI Weekly Chronicles - August'25 Week I
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Empathic Computing: Creating Shared Understanding
Reach Out and Touch Someone: Haptics and Empathic Computing

Android calculatortest