简体   繁体   English

如何模拟BluetoothAdapter.ACTION_REQUEST_ENABLE

[英]How to Mock BluetoothAdapter.ACTION_REQUEST_ENABLE

I'm trying to solve a problem with a the following code which i have got to test: I'm using Mockito and Robotium to solve the most testcases. 我正在尝试使用下面的代码来解决问题,我必须对其进行测试:我正在使用Mockito和Robotium解决大多数测试用例。 The problem is to mock an answer from the user by a request dialog started through: 问题是通过以下请求对话框模拟用户的答案:

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableBtIntent, BluetoothAdapterService.REQ_BT_ENABLE);

The answer is cached by 答案被缓存

protected void onActivityResult(int requestCode, int resultCode, Intent data) {     

    if (requestCode == 1) {                                                             /*TODO: für 1 eine Konstante verwenden, hier und in der aufrufenden Funktion*/
        if (resultCode ==   BluetoothAdapterService.REQ_BT_ENABLE) {                    /*TODO RequestCode == ResultCode dh. der COde kann hier optimiert werden*/
            btAdapterService.setBluetoothState(BluetoothAdapterService.ON);
        }
        else {
            btAdapterService.setBluetoothState(BluetoothAdapterService.OFF);            /* Wenn keine Verbindung aufgebaut werden konnte, oder die Aktivierungsaufforderung des -> */                                                                           /* BT-Adapters mit nein quittiert wurde, ist der resultCode = RESULT_CANCELD = 0 */
        }
    }
}

I have tried some solutions to get the button clicked which shows up during the test but although Iam using robotium I cant acces the button by 我已经尝试了一些解决方案来使按钮在测试过程中显示出来,但是尽管Iam使用robotium我无法通过以下方式访问按钮

solo.clickOnText("No");

Is it also possible to paste the request into another class and call a method for it? 是否还可以将请求粘贴到另一个类中并为其调用方法? So that i could reuse the request in diffrent ways? 这样我就可以以不同的方式重用请求? I tried this out but then i got the problem that no request shows up and i get an exception. 我尝试了一下,但是后来出现了没有请求出现的问题,并且出现了异常。

I'm not an indeep programmer and i have started know with this topic. 我不是一个程序员,我已经开始了解这个话题。 I would appreciate every help. 我将不胜感激。

I don't know what is purpose of your tests. 我不知道您的考试目的是什么。 As for me it sounds like you want to be sure that your code processes user's answer correctly. 对于我来说,这听起来像是要确保您的代码正确处理用户的回答。

So for me it would be enough just to call onActivityResult(1,BluetoothAdapterService.REQ_BT_ENABLE) and check after that bluetooth was enabled. 因此,对我来说,仅调用onActivityResult(1,BluetoothAdapterService.REQ_BT_ENABLE)并在启用该蓝牙后进行检查就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BluetoothAdapter.ACTION_REQUEST_ENABLE立即调用onActivityResult - BluetoothAdapter.ACTION_REQUEST_ENABLE calls onActivityResult immediately 蓝牙适配器.enable(); 在某些设备中显示没有意图 ACTION_REQUEST_ENABLE 的蓝牙启用提示 - bluetoothAdapter.enable(); shows Bluetooth enable prompt without intent ACTION_REQUEST_ENABLE in some devices registerReceiver BluetoothAdapter.ACTION_STATE_CHANGED不起作用 - registerReceiver BluetoothAdapter.ACTION_STATE_CHANGED not working Android蓝牙适配器未发出ACTION_DISCOVERY_FINISHED - Android bluetoothadapter not emitting ACTION_DISCOVERY_FINISHED 如何启用Split Action Bar? - How to enable Split Action Bar? 用于ACTION_REQUEST_ENABLE目的的startActivityForResult()大约需要6秒钟 - startActivityForResult() for ACTION_REQUEST_ENABLE intent takes ~6 seconds android studio kotlin - 蓝牙“操作请求启用”不起作用 - android studio kotlin - bluetooth "ACTION REQUEST ENABLE" doesn't work 如何启用我的应用程序以完成操作 - How to enable my app to be called to complete an action 如何启用多列的ListView点击动作? - How to Enable clickable Action in the multicolumn ListView? 以编程方式启用模拟位置 - Programmatically enable Mock Locations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM