Reputation: 435
How to get the context of the project which is under test.I have a class which is singleton,To create object for this i need to call one constructor of this class in setUp() method of testcase class,but i need to pass some context as a parameter to call that constructor, but i dont know how to get the context of this testcase class.I got confused whether i shuld pass the context of testcase class or the class which is under test.could any one help in this please.Could any one help me in this
Upvotes: 0
Views: 388
Reputation: 1254
MockContext wouldn't be a good choice, since there are no methods implemented. Every method call will give you an exception.
There is an IsolatedContext which has some stub methods implemented, but still throws a few exceptions.
If your class is extending AndroidTestCase you can simply call getContext() to receive an instance of Context.
Upvotes: 1
Reputation: 20132
you can get getApplicationContext()
or getBaseContext
or simply this
!
Upvotes: 4
Reputation: 196
Never used it myself, but the answer is probably here : http://developer.android.com/reference/android/test/mock/MockContext.html
Upvotes: 0