Reputation: 23
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. 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
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.
Upvotes: 2
Views: 1493
Reputation: 20130
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.
Upvotes: 1