Mauricio Moraes
Mauricio Moraes

Reputation: 7373

Mock device data on android tests

The devices running my android app now can send their data to a server. But I'm having trouble testing, as the device's data change from device to device.

Here's how I get some of the device data:

    String simSerialNumber = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSimSerialNumber();
    String androidVersion = Build.VERSION.RELEASE;
    String deviceModel = Build.MODEL;
    String deviceSerial =  Build.SERIAL;

How can I mock these on my tests?

Upvotes: 2

Views: 1936

Answers (1)

David Kim
David Kim

Reputation: 164

Found a really convenient way to mock device information from this posting: https://groups.google.com/forum/#!topic/robolectric/-d4aaAGB7Ks

If you use Roboelectric, you can use ReflectionHelpers class.

ReflectionHelpers.setStaticField(android.os.Build.class, "MANUFACTURER", "Manufacturer of your choice");

Upvotes: 2

Related Questions