BackupAgent, Service, Activity, Application, MockApplication,
IsolatedContext... You can figure this out by checking the
documentation for the method, which you'll see is on Wrapper (or, if
you don't look quite as far as you should, ContextWrapper, but it's
also defined one level up on Wrapper), and looking at the top of the
page where it says Known Indirect Subclasses. Or Eclipse will tell you
what class it's defined on, and you can check the class hierarchy.

Further -- you don't need to test getFilesDir(). Make a method that
accepts a File as an argument, and make your unit test test that. Then
call it with the result from getFilesDir(), and you'll eliminate one
dependency on the context. Especially, don't save the context away in
an instance field; depending on what you're doing that could be a
memory leak. Minimalizing coupling just makes sense all around.

Really in most cases, you can test most of your application's most
critical logic without any dependence on Android-specific stuff at
all, and your app will be better-modularized for the effort. Don't
take that as an iron-clad rule; it should just be a natural
consequence of well-organized testing that your unit tests will test
the functionality in isolation.

Your integration tests will have more dependencies on the Android
platform as a rule.

On Dec 15, 5:30 pm, Dianne Hackborn <[email protected]> wrote:
> On Wed, Dec 15, 2010 at 2:12 PM, gato chlr <[email protected]> wrote:
> > Kostya , you right, but then, my worry is about if i will be able to
> > do an unit test of my PersistenceUtil, how to do it without an
> > instance of an Activity?
>
> You DO NOT need to instantiate an Activity.  All you need is a Context, ANY
> Context, for your package.  Your Application object.  The Instrumentation
> class will give you one.  You can get this from all over the place.
>
> --
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to
> provide private support, and so won't reply to such e-mails.  All such
> questions should be posted on public forums, where I and others can see and
> answer them.

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

Reply via email to