2012-03-21 74 views
0

這是我的廣播接收器類來實現報警。我想單元測試這個類。單元測試接收器類

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(); 
     } 
    } 
} 

} 

我該如何實現我的測試用例來單元測試這個接收器類。我想測試我的接收器類是否正常工作。感謝您的幫助提前。

+0

看看這個問題http://stackoverflow.com/questions/4073982/why-is-there-no-test-instrumentation-for-broadcastreceiver – Axxiss 2012-12-01 15:32:36

回答