Robotium如何与后台服务,如转换测试? [英] Robotium How to test with background Services like conversion?

查看:113
本文介绍了Robotium如何与后台服务,如转换测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Robotium录音机来测试我的应用程序。我的问题是在我的应用我正在基于多少时间用户记录在做背景,还需要一段时间的音频转换。

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.

示例

如果我运行一个测试,记录了10分钟这样每次(转换背景)的10倍,它记录这样的当我最后一次记录是10日录制完成robotium退出并杀死应用程序。

If i am running a test which records for 10mins (Converts in background) each time like this 10 times it records so when my last recording that is 10th recording finishes robotium exits and kill the app.

**问题: - 对于最后的录音我的文件仍然需要转换其背景(服务),但应用程序转换是杀了那么转换失败。我不能使用solo.sleep(INT),因为我不知道这将需要多长时间来转换**

推荐答案

最后我得到了解决。

testRun()函数调用 isServiceRunning()功能。

public void testRun() {
    .
    .
    if(isSurviceRunning()) {
        solo.sleep(time);
    }
}

这为您的应用程序的后台服务的方法检查,并返回boolean值。

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());
        return true;
    } else {
        Log.d("false", "" + service.service.getClassName());
    }
}
return false;
}

这篇关于Robotium如何与后台服务,如转换测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆