AndroidTestCase.getContext() returns a normal Context object. It's the Context of the test case, not the component under test.
IsolatedContext returns a "mock" Context. I put "mock" in quotes because its not a mock in the normal sense of that term (for testing). Instead, it's a template Context that you have to set up yourself. It "isolates" you from the running Android system, so that your Context or your test doesn't accidentally get outside of the test fixture. For example, an IsolatedContext won't accidentally hit a production database (unless you set it up to do that!) Note, however, that some of the methods in an IsolatedContext may throw exceptions. IsolatedContext is documented in the Developer Guide under Framework Topics > Testing, both in Testing Fundamentals and in Content Provider Testing. You haven't said anything more about what you're trying to test, but I find it interesting that you're using AndroidTestCase instead of one of the more specific classes. Any reason for this? Elkmeister. On Jan 9, 11:56 pm, Mattias Svala <[email protected]> wrote: > Hello! > > I'm writing some tests to test my database code. Can someone here explain if > there would be a difference writing those tests using the context I get from > AndroidTestCase.getContext() or using an IsolatedContext. > > Speaking of IsolatedContext, what is the easiest way to create one if I just > need it for some sqlite database testing? > > Regards, > Mattias -- 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

