android - Testing an outgoing intent -
i've been trying unit test simple calculator app activityunittestcase
. code calculator app
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_page); disp = (textview) findviewbyid(r.id.disp); n1 = (edittext) findviewbyid(r.id.n1); n2 = (edittext) findviewbyid(r.id.n2); calc = (button) findviewbyid(r.id.calc); calc.setonclicklistener(this); } public void onclick(view v) { double num1 = double.valueof(n1.gettext().tostring()); double num2 = double.valueof(n2.gettext().tostring()); intent in = new intent(this,calcactivity.class); in.putextra("num1",num1); in.putextra("num2", num2); startactivity(in); }
i want able perform operations on 2 numbers , send through intent. question is, how examine contents of outgoing intent during unit test ?
found it. there's function in activityunittestcase
trick.
intent in = getstartedactivityintent();
which return launch intent if activity under test calls startactivity(intent)
or startactivityforresult(intent, int)
.
Comments
Post a Comment