I am trying to setup JUnit test cases for an app I am developing currently. The main problem I am facing is that I am not able to get access of an object which I am storing in my Application class. I am extending the AndroidTestCase class for writing test cases.
I tried getting access to that object(say myData) by
Myapp app = (Myapp) getContext()
.getApplicationContext();
String myData=app.getData();
But this is throwing null pointer exception at app.getData(); how can i access this object at run time?
Please, show more code, class where extends AndroidTestCase
, class where extends TestSuite
Also, you may forget add to AndroidManifest :
...
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="YOUR_PACKAGE"/>
<application
android:label="@string/app_name"
android:name="YOUR_APPLICATION_CLASS">
<uses-library android:name="android.test.runner"/>
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.