views:

686

answers:

2

I am trying to test my DB using ProviderTestCase2<T>. I can see the test DB being created. As such I suppose, the tested content provider should use the test DB. But as soon as I try any calls against the MockContentResolver (or the one created with newResolverWithContentProviderFromSql), I get an UnsupportedOperationException. This is documented for the MockContentResolver as normal behavior. As such I am a bit unsure on the purpose of the ProviderTestCase2.

How do you test your content providers?

Thanks

+1  A: 

Extend ProviderTestCase2 to override getMockContentResolver() and return your own class derived from MockContentResolver.

public class MyProviderTestCase2 extends ProviderTestCase2 {
    @Override
    public MockContentResolver getMockContentResolver () {
        return new MyMockContentResolver();
    }
}

MyMockContentResolver will need to override any methods you want to test in your ContentProvider.

Then you should be able to run any tests you want on your content provider while it's isolated by ProviderTestCase2

Mike
A: 

Hi everybody i want to learn is there any way to access mysql database from android? thanks in advance

kurtulus