David Guo
David Guo

Reputation: 1759

How to get the activity or application context in AndroidTestCase

I am writing some test case with AndroidTestCase. I want call getCacheDir to get the directory.

/data/data/com.mypackage/cache

But I have not start up the activity or application. it there any way I can get the activity or application context in AndroidTestCase.

Upvotes: 0

Views: 724

Answers (2)

Aster
Aster

Reputation: 877

Since you are extending the AndroidTestCase, you can just use the call getContext() to retrieve the context. AndroidTestCase implements it for you.

Upvotes: 0

nyjsl
nyjsl

Reputation: 311

you can simply override getContext() in you subclass of AndroidTestCase

Upvotes: 1

Related Questions