java - Robolectric Test an activity launched from a widget -


i've simple widget consists of image , button, button should launch activity. i'm trying write robolectric test test activity launched when button clicked

i've 2 problems, firstly i'm getting npe when attempting click button:

java.lang.nullpointerexception: can't shadow null    @ org.robolectric.bytecode.shadowwrangler.shadowof(shadowwrangler.java:415)    @ org.robolectric.robolectric.shadowof_(robolectric.java:1020)    @ org.robolectric.robolectric.shadowof(robolectric.java:671)    @ org.robolectric.shadows.shadowintent.fillin(shadowintent.java:454)    @ android.content.intent.fillin(intent.java)    @ org.robolectric.shadows.shadowpendingintent.send(shadowpendingintent.java:48)    @ android.app.pendingintent.send(pendingintent.java)    @ org.robolectric.shadows.shadowremoteviews$2$1.onclick(shadowremoteviews.java:61)    @ android.view.view.performclick(view.java:4084) 

also i'm not sure how reference activity launched via button click.

code test:

@test public void buttonshouldlaunchactivity() throws exception {     int widgetid = shadowappwidgetmanager.createwidget(hellowidgetprovider.class, r.layout.hellowidget_layout);     view hellowidgetview = shadowappwidgetmanager.getviewfor(widgetid);     button quickbutton = (button) hellowidgetview.findviewbyid(r.id.quick_add_button);     quickbutton.performclick();      // not sure how handle of activity started widget, have activity launched activity.     intent intent = robolectric.shadowof(activity).peeknextstartedactivity();     assertequals(quickaddactivity.class.getcanonicalname(), intent.getcomponent().getclassname()); } 

any thoughts apreciated, actual widget working (the activity launched) i'd have test it.

peeknextstartedactivity() method on shadowapplication. method on shadowcontextwrapper (which shadowactivity implicitly uses) wrapper calls 1 on shadow application.

so should able this, need:

robolectric.getshadowapplication().peeknextstartedactivity() 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -