A MockContext is a completely stubbed out context, so all of the
methods on it throw UnsupportedException().  If there is some specific
piece of functionality on Context that you want to mock, you make a
subclass of MockContext and hand that to the code to be tested,
allowing it to call back on your mock implementation.

For your specific case of openDatabase(), you will need to either make
a subclass that implements that method as you desire (for example
making an in-memory database), or get a real context and use that.

On Apr 5, 12:44 pm, "fernan.do" <[EMAIL PROTECTED]> wrote:
> Hi Everyone,
> I am trying to test my database CRUD methods. To do so I need to
> create a Context since Android's openDatabase and so on are invoked
> from the Context class. I was sure that one way to do so was to create
> a MockContext() and use that to invoke the mehtods. This is not
> working, the following piece of code gives me an
> UnsuportedOperationException:
>
> private MockContext context=new MockContext();
>  mDb = context.openDatabase(DATABASE_NAME, null);
>
> I am not sure why this is happening, since on the references pages
> these methods seem to be supported but since we do not have access to
> the source I am not really sure what is happening. Any one has run
> into a problem like this?
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Android Internals" 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-internals?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to