KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm new into Android testing, I want to test an IntentService and I'm currently extending ServiceTestCase. I'm trying to use a ResultReceiver but the problem is that OnReceiveResult is never called within the test case. (I also tried creating the ResultReceiver with new Handler() as the argument insetad of null but with the same result. what am I doing wrong? what is the proper way to test an IntentService ? this is the service: public class MyService extends IntentService { public MyService() { super("MyService"); } public MyService(String name) { super(name); } @Override protected void onHandleIntent(Intent intent) { final int action = intent.getIntExtra("action", 0); final int request = intent.getIntExtra("request", 0); final ResultReceiver receiver = (ResultReceiver) intent.getExtras().get("receiver"); if (receiver == null) { return; } if (action == 0 || request == 0) { receiver.send(0, null); return; } } } and this is the test: public void testHandleInvalidRequests() { ResultReceiver receiver = new ResultReceiver(null) { @Override protected void onReceiveResult(int resultCode, Bundle resultData) { fail(); } }; Intent intent = new Intent(mContext, MyService.class); intent.putExtra("receiver", receiver); startService(intent); }
Tags (comma-separated)
Save Edits
Cancel