Android Testing: Can I send sms to the emulator number from test method?
I have received some code from another team and started to simple improvement and re-factoring. The first phase is adding unit test to the project. I need to test functionality of parsing input sms. Related to above information my question is: - Can I send sms to the emulator port from test method? I have writen next code but have no received anything ...
@Test
public void sendSmsTest() {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTe开发者_开发问答xtMessage("5554", null, getSms("sms1"), null, null);
}
private String getSms(String smsKey) {
return (String) smsMessages.get(smsKey);
}
Thanks.
After restarting emulators and IDE I have received next error in console:
Test running failed: Exception thrown in onCreate() of ComponentInfo{com.example/android.test.InstrumentationTestRunner}: java.lang.NullPointerException
Use something like from the host computer
$ adb emu sms send 5551234 Hello Android
To send SMS to a specific emulator:
$ adb -s emulator-5554 emu sms send 5551234 Hello Android
I started 2 emulator instances and was able to send an SMS from instance to the other, but... I had a problem where it would only send from the second instance I started. Look at this post:
Sending sms text message from android emulator to second emulator instance
精彩评论