Robotium How To Test With Background Services Like Conversion?
I am using Robotium Recorder to test my app. My problem is in my app i am doing audio conversions in background which take some time based on how much time user is recording. Exam
Solution 1:
You can use solo.waitForCondition()
finalintTIMEOUT=5000;
Assert.assertTrue(solo.waitForCondition(newCondition() {
@OverridepublicbooleanisSatisfied() {
// return true if the file has been converted.
}
}, TIMEOUT));
Solution 2:
Finally i got the solution
In testRun()
function call isServiceRunning()
function.
public void testRun() {
.
.
if(isSurviceRunning()) {
solo.sleep(time);
}
}
This method check for background services of your app and return boolean.
public boolean isServiceRunning() {
ActivityManager manager = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if ("com.pakage.name.yourcls.your_service_name".equals(service.service.getClassName())) {
Log.d("Running Service is->", "" + service.service.getClassName());
returntrue;
} else {
Log.d("false", "" + service.service.getClassName());
}
}
returnfalse;
}
Post a Comment for "Robotium How To Test With Background Services Like Conversion?"