Vous êtes sur la page 1sur 8

Robotium User Manual

Version 1.0
Table of Contents
1. Robotium :...........................................................................................................................3
Robotium provides the following benefits:.............................................................................3
2. How to use Robotium :........................................................................................................3
3. Sample Robotium Test lass:..............................................................................................!
!. "reating a #ase Robotium Test Sript:...............................................................................$
$. %dvantages of Robotium: ...................................................................................................&
1. Robotium :
't is an open(soure test framewor) for writing automati bla)(bo* test ases for
%ndroid appliations. +ith the support of Robotium, test ase developers an write
funtion, s-stem and aeptane test senarios, spanning multiple %ndroid ativities.
Robotium an be used both for testing appliations where the soure ode is available
and appliations where onl- the %./ file is available and the implementation details are
not )nown.
Robotium an be used with all the different build automation tools.The framewor) is
released under Apache License 2.0. 'ts founder and main developer is Renas Reda.
Version 3.$.1 was released on 0tober 11, 2012. Robotium is similar to Selenium, but
for %ndroid. 't has support for %ndroid features suh as ativities, toasts, menus and
onte*t menus.
Robotium provides the following benefits:
1ou an develop powerful test ases, with minimal )nowledge of the appliation
under test.
The framewor) handles multiple %ndroid ativities automatiall-.
2inimal time needed to write solid test ases.
Readabilit- of test ases is greatl- improved, ompared to standard
instrumentation tests.
Test ases are more robust due to the run(time binding to 34' omponents.
5ast test ase e*eution.
'ntegrates smoothl- with 2aven or %nt to run tests as part of ontinuous
integration.
2. How to use Robotium :
1. "reate a sample %ndroid Test .ro6et
2. %dd the Robotium 6ar to -our pro6et build path.
3. 3ive the pro6et whih -ou want to test as Referene to this Test .ro6et.
!. "reate Robotium test sripts.
3. Sample Robotium Test class:
"reate a "lass file to reate test sript e*tending
from%tivit-'nstrumentationTest"ase2.
'mport android.test.%tivit-'nstrumentationTest"ase2 for reating 6unit test for
%ndroid appliations.
'mport om.6a-wa-.android.robotium.solo.Solo to write automation sripts using
Robotium.


Example :
pa)age om.e*ample.testdemo.test7
import android.test.%tivit-'nstrumentationTest"ase27
import om.e*ample.testdemo.2ain%tivit-7
import om.6a-wa-.android.robotium.solo.Solo7
publi lass Test"lass e*tends %tivit-'nstrumentationTest"ase282ain%tivit-9 :
private Solo solo7
publi Test"lass;< :
super;2ain%tivit-.lass<7
=
publi void set4p;< throws >*eption :
solo ? new Solo;get'nstrumentation;<, get%tivit-;<<7
=
publi void test.referene'sSaved;< throws >*eption :
@@ "he) that we have the right ativit-
solo.assert"urrent%tivit-;Awrong ativi-A, 2ain%tivit-.lass<7
solo.li)0nTe*t;BRun this Te*tC<7
solo.lear>ditTe*t;2<7
%ssert.assertTrue;solo.searhTe*t;BrtfC<<7
solo.enterTe*t;2, BrobotiumC<7
solo.goba);<7
solo.li)0n#utton;A3et >ventDistA<7
solo.li)0n#utton;A'nitial >ventA<7
solo.li)0nTe*t;AE>FTA<7
=
G0verride
publi void tearHown;< throws >*eption :
solo.finish0pened%tivities;<7
=
=
. Creating a !ase Robotium Test Script:

private Solo solo7
@@ 'ntialiIing S0D0 ob6et and ma)ing to refer %ppliationToTest
G0verride
proteted void set4p;< throws >*eption :
solo ? new Solo;get'nstrumentation;<, get%tivit-;<<7
=
@@ This methods ontains the atual sript to perform on %ppliation
publi void test"an0penSettings;<:
solo.press2enu'tem;0<7
=
@@ This 2ethod destro-s the Solo ob6et J loses the app
G0verride
publi void tearHown;< throws >*eption :
tr- :
solo.finaliIe;<7
=
ath ;Throwable e< :
e.printSta)Trae;<7
=
get%tivit-;<.finish;<7
super.tearHown;<7
=
=
i. Object Identiication
Robotium provides basi ob6et identifiation methods li)e 'nde* and Visible Te*t. 'f we
have aess to the soure ode of the %ppliation(4nder(Test ;%4T< or developers ould
provide details about 'HKs assigned to eah ontrol, it ma)es development of test sripts
muh more robust and simpler.
However it is not possible to find out the 'HKs assigned to eah ontrol, we will have to
use 'nde* or Visible Te*t properties to perform ations on the ontrols.
'f we have to write sript based on 'nde* or Dogial te*t and there are two edit bo*es on
the sreen, the- will have 'nde* 0, 'nde*1 respetivel-, in the order the- appear on the
sreen.
ii. !o Enter !ext in Editbox
solo.enterTe*t;0,CLLL1111LLLC<7
solo.enterTe*t;1,CdemouserC<7
iii. !o "lic# on "ommand button ha$in% caption &'end 'M'(
solo.li)0n#utton;BSend S2SC<7
i$. Usin% Re%ular Expression or Object Identiication
+e an also use regular e*pressions to help with identifiation of ob6ets for writing test
sripts.

Example:
'f appliation ontains 4' as below.
1. Regular e*pression an also be used for performing ations as well as
s-nhroniIing the e*eution of the test sripts with %4T.
Actions: To li) on button we an sript as follows.
solo.li)0n#utton;B.MDist.M"he)bo*esC<7
$. ')nchroni*ation:

To wait till the window having the te*t NwwwK e*ist, we an sript as below

solo.wait5orTe*t;B.Mwww.MC<7
$i. Application +eplo)ment
#efore proeeding to e*eution of sripts, deplo- the appliation ;ap)< to test on Target
Hevie ;Simulator or 2obile Hevie<.
,ii. 'cript Execution
+e an e*eute sripts either from within elipse or from ommand prompt or from
devie ;if Test %./ is alread- deplo-ed<.
To run the test sript from within >lipse, Right li) on .ro6et and selet Run as
(9%ndroid Ounit Test.
Eote: #efore running ma)e sure that %4T is deplo-ed J having same signature as test
pro6et
". #dvantages of Robotium:
1. Supports h-brid appliations with webViews.
2. Robotium greatl- improves effiien- of tests
3. Robotium is an open soure pro6et, so we an modif- tool to our needs.

Vous aimerez peut-être aussi