I have noticed that every now and then there is a question about using Robolectric for testing custom ContentProviders. However, there has never been a concrete and unambiguous answer on how to do it properly. I have stumbled upon 2 different approaches:
one saying you can simply instantiate an in-memory ContentProvider, which you can use to insert and query data (https://gist.github.com/anonymous/6139359)
the other saying to use the ShadowContentResolver to set mock cursor data (https://groups.google.com/d/msg/robolectric/r35mMirIkTs/xJJBNXl_RgwJ)
However, I'm getting a java.lang.InstantiationException with both approaches. There have been some SO posts saying that this is due to SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java) not being overriden in Robolectric (Android + Robolectric - RuntimeException / InstantiationException in queryBuilder.query() in ContentProvider).
I guess my question is - are there any preffered workarounds that make testing ContentProviders possible. Or are there any other approaches that are better then those 2 mentioned above.