开发者

Android Testing: Can I send sms to the emulator number from test method?

开发者 https://www.devze.com 2023-03-17 00:35 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号