java - NPE when creating visible Activities Robolectric 2.3 -
for illustration have 2 activities mainactivity , nextstartedactivity.
oncreate() method in mainactivity
... intent intent = (new intent(this, nextstartedactivity.class).putextra("start", 1)); startactivity(intent);
for mainactivity invocation works fine
activity = robolectric.buildactivity(mainactivity.class).create().visible().get();
oncreate() in nextstartedactivity
... request_status = getintent().getextras().getint("start"); textureview.setsurfacetexturelistener(this); ...
when utilize invocation above nextstartedactivity, have java.lang.nullpointerexception @ nextstartedactivitytest.java:89
when use
activity = robolectric.buildactivity(nextstartedactivity.class).get();
all works fine.
please, give me understanding in differences of ways different activities. , equal setupactivity()?
if npe occurring on line:
request_status = getintent().getextras().getint("start");
then problem not creating intent in test, code expects. seek this:
intent intent = new intent(robolectric.getshadowapplication().getapplicationcontext(), nextstartedactivity.class); intent.putextra("start", 1); robolectric.buildactivity(nextstartedactivity.class).withintent(intent).create().get();
java android unit-testing robolectric
No comments:
Post a Comment