What is the Provider Authority String in ProviderTestCase2 constructor?
Can you please tell me what is Provider Authority String in ProviderTestCase2 constructor?
From the JavaDoc below http://developer.android.com/reference/android/test/ProviderTestCase2.html
it requires 'Provider Authority String', my question 开发者_运维百科I am using it to unit test my Content Provider, so what is my Provider Authority String?
Thank you.
In you application's AndroidManifest.xml
you declare your provider in a next way:
<provider android:name=".provider.MyProvider"
android:authorities="com.company.app.provider"/>
In your ProviderTestCase2
class you should then specify com.company.app.provider
as second parameter to super constructor.
For example:
public class MyProviderTest extends ProviderTestCase2<MyProvider>
{
public MyProviderTest()
{
super(MyProvider.class, "com.company.app.provider");
}
}
you should write the code:
public void setup () {
mContactProvider = mProviderClass.newInstance();
Context context = getContext();
mContactProvider.attachInfo(context, null);
mMockContentResolver.addProvider(authority, mContactProvider);
}
then you can operate your contentprovider data
精彩评论