0

this is my broadcast receiver class to implement alarm .I want to unit test this class.

public class AlarmReceive extends BroadcastReceiver{
//DeviceIntelligence di;
Registration rs;
ServerUpload su;

@Override
public void onReceive(Context context, Intent intent) {
    rs = new Registration();
    su = new ServerUpload();

    if (intent.getAction().equals("APP_LIST_INSERT_SIGNAL")) {

    }

    Log.d("operator", "alarm action: " + intent.getAction());
    if(intent.getAction().equals("SERVER_UPLOAD_SIGNAL_PER_HOUR")){
        rs.uploadServerData(context);
    }

    if(intent.getAction().equals("SERVER_UPLOAD_SIGNAL_PER_DAY")){
        rs.uploadServerData(context);
        if(MainService.dh.selectAll().size() != 0){
            MainService.dh.deleteAll("TABLE_NAME");
        }

        if(Registration.ud.select().size() != 0){
            Registration.ud.deleteAll();
        }

        if(Registration.wid.selectAll().size() != 0){
            Registration.wid.deleteAll();
        }

        if(Registration.dch.allSelect().size() != 0){
            Registration.dch.deleteAll();
        }
    }
}

}

how can I implement my test case to unit test this receiver class.I want to test my receiver class is working properly or not. thanks for your help in advance.

thej
  • 648
  • 10
  • 33
  • Take a look to this question http://stackoverflow.com/questions/4073982/why-is-there-no-test-instrumentation-for-broadcastreceiver – Axxiss Dec 01 '12 at 15:32

1 Answers1

0

You can use MockContext to "simulate" the broadcast. See here for more details: Unit testing a broadcast receiver?

Community
  • 1
  • 1
GabrielWeis
  • 340
  • 1
  • 3
  • 13