March 2015
Beginner to intermediate
274 pages
6h 1m
English
Sometimes, memory consumption is an important factor to measure the good behavior of the test target, be it an Activity, Service, Content Provider, or another component.
To test for this condition, we can use a utility test that you can invoke from other tests mainly after having run a test loop:
public void assertNotInLowMemoryCondition() {
//Verification: check if it is in low memory
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
((ActivityManager)getActivity()
.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
assertFalse("Low memory condition", mi.lowMemory);
}This assertion can be called from other tests. At the beginning, it obtains MemoryInfo from ActivityManager using getMemoryInfo() ...
Read now
Unlock full access