Sunday, January 8, 2012

[android-developers] Re: Android unit testing with ContentProviders and databases

To expand on my last message, in run mode, the database created is a
'live' one. I.e. without a "test." prefix. This means it is not
deleted in my tear down and tests fail.

Thanks,
Bary

On Jan 8, 8:31 pm, Barry Drinkwater <barry.drinkwa...@gmail.com>
wrote:
> Hi,
>
> I'm having strange problems with my RenamingDelegatingContext. It
> successfully creates a test database when I run the tests in debug mode,
> but only *sometimes* in 'run' mode (I'm using eclipse).
>
> I can't figure this out. Any ideas?
>
> Barry
>
> On 2 January 2012 06:18, Diego Torres Milano <dtmil...@gmail.com> wrote:
>
>
>
>
>
>
>
> > The best solution is probably a RenamingDelegatingContext, that will
> > allow your tests to use a different database than your 'live' one.
> > There are examples of RenamingDelegatingContext and other mock
> > injections in Android Application Testing Guide [http://
> >www.packtpub.com/android-application-testing-guide/book].
>
> > On Dec 31 2011, 2:20 am, Stephan Wiesner <testexpe...@googlemail.com>
> > wrote:
> > > I guess you gave the obvious answer yourself: Don't hardcode the name.
> > > Use a variable, maybe a system setting or something from a config file
> > > that can be accessed by all your apps and put an if/else block in your
> > > provider....
>
> > > Greetings from Berne,
> > > Stephan
>
> > > On 31 Dez., 01:05, barry <barry.drinkwa...@gmail.com> wrote:
>
> > > > I have an app that uses a ContentProvider to serve data instead of
> > > > directly accessing the database. The application is working as
> > > > expected but I have a problem with unit tests: how can I force the
> > > > ContentProvider to use a test database rather than a 'live' one? If I
> > > > wasn't using a ContentProvider I could pass a different database name
> > > > to the Constructor of my `SQLiteOpenHelper` sublass, but now the
> > > > database is created with a call to onCreate() in my ContentProvider:
>
> > > >         @Override
> > > >         public boolean onCreate()
> > > >         {
> > > >                 UKMPGDataProvider.init(getContext(),
> > Constants.DATABASE_NAME);
> > > >                 return (UKMPGDataProvider.getWritableDatabase() ==
> > null) ? false :
> > > > true;
> > > >         }
>
> > > > As you can see, the database name is hardcoded.
>
> > > > Is there a way to pass a test name into the ContentProvider?
>
> > --
> > Have you read my blog ?
> >http://dtmilano.blogspot.com
> > android junit tests ui linux cult thin clients
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate