I am writing test cases for android app classes. But I am unable to find a way to get context of this class. Below is my test case class.
public class SplashScreenActivityTest extends TestCase {
SplashScreenActivity splashScreenActivity;
Context context;
public void setUp() throws Exception {
super.setUp();
splashScreenActivity = new SplashScreenActivity();
}
public void testDeviceDetailsPost() throws Exception {
//I need to access a method here which requires context
}
}
I looked through many questions but I cannot understand their answers.
For example this question Get context of test project in Android junit test case
You can pass the instance variable
context
to the method that requires it as followsmethodThatRequiresContext(context);
I'm not entirely sure what your difficulty is.