java - how to get value thats displayed in the Emulator? -


i writing small android "hello world" application , write small test case . have written small test case , have below :

public void testmyfirsttesttextview_labeltext() {     final string expected = getcontext().getresources().getstring(r.string.hello_world);     final string actual = getcontext().gettext().tostring();     assertequals(expected, actual); } 

the expected variable gets instantiated value strings.xml
actual value , struggling understand methods or snippet should write in order value of displayed string .

so how value of text displayed in emulator: of below statement wrong:

final string actual = getcontext().gettext().tostring(); 

i new android , can me please .

if check last peice of code in snippet :

assertequals(expected, actual); 

it checks(using junit think) weather value of expected same actual.

once again repeat question in above snippet , how get/retrive value of displayed text ? i.e. on below line :

final string actual = getcontext().gettext().tostring();   

it should yourtextviewobject.gettext() not getcontext().gettext()

textview textview = (textview)findviewbyid(r.id.hello_world);//assuming id in xml page textview1 string actual = textview.gettext().tostring(); 

this gets value of entry hello_world strings.xml.

string expected = getcontext().getresources().getstring(r.string.hello_world); 

and gets value textview.

string actual = textview.gettext().tostring(); 

from android documentation's example

mfirsttesttext = (textview) mfirsttestactivity                 .findviewbyid(r.id.my_first_test_text_view);  string actual = mfirsttesttext.gettext().tostring(); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -