Testing a custom ContentProvider in Android -
i have written content provider supposed wrap access 2 tables in sqllite database. i'd write test cases have never done it. after reading section on developer guide, must did not manage tested.
below code far. class in test project corresponds main project. when execute in eclipse, emulator starts correctly, packages installed not run test:
test run failed: test run incomplete. expected 1 tests, received 0
here test class:
public class articleprovidertest extends providertestcase2<articleprovider> { static final uri[] validuris = new uri[] { articles.content_uri, pictures.content_uri, pictures.getcontenturiforarticleid(1) }; public articleprovidertest(class<articleprovider> providerclass, string providerauthority) { super(providerclass, providerauthority); } @override protected void setup() throws exception { super.setup(); } public void testquery() { contentprovider provider = getprovider(); (uri uri : validuris) { cursor cursor = provider.query(uri, null, null, null, null); assertnotnull(cursor); } } }
and manifest file, if helps:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="fr.marvinlabs.xxxx" android:versioncode="1" android:versionname="1.0"> <uses-sdk android:minsdkversion="7" /> <instrumentation android:targetpackage="fr.marvinlabs.xxxx" android:name="android.test.instrumentationtestrunner" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <uses-library android:name="android.test.runner" /> </application> </manifest>
when launch in debug configuration, breakpoints in constructor , in setup don't triggered. ?!
i did not find info on net. me understanding on how testing should setup (basically create test database file, fill data, query it, ...)?
ok, got it. mistake was not providing default constructor test class. had overridden wrong constructor:
public articleprovidertest(class<articleprovider> providerclass, string providerauthority) { super(providerclass, providerauthority); }
is
public articleprovidertest() { super(articleprovider.class, "com.blah.azerty"); }
2am time when cannot read docs entirely well, afternoon better :)
Comments
Post a Comment