android - Robolectric: failed on start test cause of wifi start scan -
i've created little test under robolectric. unfortunately, must comment these lines having success test :
public class myapplication extends application { private void setupapplication() { .... //mnetworkevents = new networkevents(this, eventbus.getdefault()) // .withpingurl(buildconfig.ping_server_url) // .withpingtimeout(buildconfig.ping_timeout); }
this class "networkevents" allows test internet connectivity. , in class there call:
public static void startwifiscan(context context) { wifimanager wifimanager = (wifimanager) context.getsystemservice(context.wifi_service); wifimanager.startscan(); }
and problem start wifi scan...
this error:
java.lang.nullpointerexception @ android.net.wifi.wifimanager.startscan(wifimanager.java:995)
how can run test without comment these line in application class ??
thanks guys!
i've tried reproduce error , found same. thinking should first set wifimanager
start using it. problem deeper.
robolectric has shadow class wifimanager
, returned startscan()
method not shadowed , trying call real class android. if take sources there service
field, implementation of wifi details, in real class , null when running robolectric.
i created issue on robolectric github https://github.com/robolectric/robolectric/issues/1969
Comments
Post a Comment