robolectric / robolectric

Android Unit Testing Framework
http://robolectric.org
Other
5.83k stars 1.36k forks source link

Add a fake implementation of MediaStore content provider #8492

Open saket opened 9 months ago

saket commented 9 months ago

Is your feature request related to a problem? Please describe. Considering that robolectric already implements Environment.getExternalStoragePublicDirectory() and related functions for file storage, it'd be nice if context.contentResolver.insert("content://media…") and context.contentResolver.query("content://media…") functions were also usable in robolectric tests.

Describe the solution you'd like Could robolectric add a fake implementation of MediaStore?

hoisie commented 9 months ago

There is something very very low quality here:

https://github.com/robolectric/robolectric/blob/master/shadows/framework/src/main/java/org/robolectric/shadows/ShadowMediaStore.java

hoisie commented 9 months ago

Also could Robolectric.setupContentProvider(ContentProviderClass, authority) help here?

https://github.com/robolectric/robolectric/blob/master/robolectric/src/main/java/org/robolectric/Robolectric.java#L66-L68

You could create a fake MediaStore content provider.

saket commented 9 months ago

You could create a fake MediaStore content provider.

Yep this is what I ended up doing, but it'd be really nice if I didn't have to maintain this code 😄. An implementation provided by robolectric would be battle tested.