Android: Error in functional testing -


i have android tab layout swipeable views.

the file structure follows:

there activity class: tabmainactivity.java, under activity, there fragment class named booklockerfragment.java.this fragment class linked xml file contains various buttons. code follows,

public class booklockerfragment extends fragment { button btnsis; public view oncreateview(layoutinflater inflater, viewgroup container,     bundle savedinstancestate) {     rootview = inflater.inflate(r.layout.fragment_booklocker, container, false);     btnsis = (button) rootview.findviewbyid(r.id.btnsis);  } ....... } 

i wrote code test functionality whether can launch next activity(populatelockerlist.java) when click button, manually tested , works however, error: junit.framework.assertionfailederror when run junit test. below test code:

package com.example.mobilelog6.test;   public class booklockerfragmenttest extends activityinstrumentationtestcase2<tabmainactivity>{      private static final string new_text = "new text";      private tabmainactivity activity;       public booklockerfragmenttest() {         super(tabmainactivity.class);       }        protected void setup() throws exception {             super.setup();             setactivityinitialtouchmode(false);             activity = getactivity();           }              public void testfragment() {             fragment frag =                activity.getsupportfragmentmanager().findfragmentbytag("search/book lockers");                                    button sisbutton = (button)getactivity().findviewbyid(r.id.btnsis);             assertnotnull("button not allowed null", sisbutton);             assertequals("incorrect label of button", "sis",                               sisbutton.gettext());              button soebutton =(button)getactivity().findviewbyid(r.id.btnsoesoss);             assertnotnull("button not allowed null", soebutton);             assertequals("incorrect label of button", "soe/soss",                soebutton.gettext());              button lkcsbbutton =                 (button)getactivity().findviewbyid(r.id.btnlkcsb);             assertnotnull("button not allowed null", lkcsbbutton);             assertequals("incorrect label of button", "lkcsb",                   lkcsbbutton.gettext());              button soabutton =                  (button)getactivity().findviewbyid(r.id.btnsoasol);             assertnotnull("button not allowed null", soabutton);             assertequals("incorrect label of button", "soa/sol",                  soabutton.gettext());              button allschoolsbutton =                 (button)getactivity().findviewbyid(r.id.btnallschools);             assertnotnull("button not allowed null", allschoolsbutton);             assertequals("incorrect label of button", "all schools",                 allschoolsbutton.gettext());              button lv2button = (button)getactivity().findviewbyid(r.id.btnlvl2);             assertnotnull("button not allowed null", lv2button);             assertequals("incorrect label of button", "lv 2",                 lv2button.gettext());              button viewlockerbutton =                   (button)getactivity().findviewbyid(r.id.btnview);             assertnotnull("button not allowed null", viewlockerbutton);             assertequals("incorrect label of button", "view locker                    selection", viewlockerbutton.gettext());              activitymonitor monitor =                     getinstrumentation().                       addmonitor(populatelockerlist.class.getname(), null,                  false);              touchutils.clickview(this, allschoolsbutton);             touchutils.clickview(this, viewlockerbutton);            populatelockerlist startedactivity = (populatelockerlist) monitor                 .waitforactivitywithtimeout(10000);             assertnotnull(startedactivity);              listview mlistview = (listview)                 startedactivity.findviewbyid(r.id.listviewlockers);             textview entryview = (textview) mlistview.getchildat(0);             string viewtext = entryview.gettext().tostring();             assertequals("incorrect label of listview 0", "view locker                               selection", viewtext);         }                } 

error @ line:

 assertnotnull(startedactivity); 

please help

i had same problem , solve it.

  1. you have sure package of project testing declared in manifest of project using test it, this:

note: suppose "targetpackage" may "com.example.mobilelog6"

  1. you have sure activity tabmainactivity starts activity populatelockerlist
  2. in method testfragment() of class booklockerfragmenttest, have "simulate" event used in tabmainactivity (i.e. click event of button) start activity populatelockerlist before call

    populatelockerlist startedactivity = (populatelockerlist) monitor.waitforactivitywithtimeout(10000);

i have seen call 2 events before call

monitor.waitforactivitywithtimeout(10000)        touchutils.clickview(this, allschoolsbutton);  ,       touchutils.clickview(this, viewlockerbutton); 

so, maybe need start activity populatelockerlist 1 of buttons in activity tabmainactivity. instance:

button addbutton = (button) findviewbyid(r.id.btnallschools);            addbutton.setonclicklistener(new onclicklistener() {                 public void onclick(view v) {                                       showsecondaryactivity();                }            }); private void showsecondaryactivity() {         startactivity(new intent(this,populatelockerlist .class));         } 

i expect, can you


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -