Search code examples
javaandroidunit-testing

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


Solution

  • 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