简体   繁体   中英

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.sendTextMessage("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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM