Bluetooth unit testing

950 views
Skip to first unread message

Bryce Penberthy

unread,
Apr 17, 2012, 6:06:25 PM4/17/12
to robol...@googlegroups.com
Hey guys,
 
First of all, thanks to everyone involved in the Robolectric project for an incredible tool for testing Android apps! 
 
Is anyone using Robolectric to test Bluetooth connection logic?  I have an app with some simple Bluetooth logic to connect to a barcode scanner.  I'm having a little trouble getting a "BluetoothDevice" object created so I can use it in a ShadowBluetoothAdapter.  Has anyone tried this?
 
Thanks!
 
Bryce
 

Matt Wolfe

unread,
Jan 14, 2013, 7:28:19 PM1/14/13
to robol...@googlegroups.com
Did you ever figure anything out on this? I am also trying to test some part of my application that deals with connecting to bluetooth devices.
I see that in ShadowBluetoothAdapter there is a setBondedDevices method.
However, I'm not sure how to create a set of BluetoothDevice objects because the constructor is not available. I found in Robolectric there is a method to create a new object with a private constructor - Robolectric.newInstanceOf(String class)
However I won't be able to set the address and name for the bluetooth device as I would like to. There is ShadowBluetoothDevice with a setName method and I can add setAddress methods to it easy enough, however if I create a set of these I can't pass them to BluetoothAdapter.setBondedDevices as it takes a Set of BluetoothDevice objects, not ShadowBluetoothDevice objects. 

Any ideas?

András Kövi

unread,
Jan 15, 2013, 2:52:40 AM1/15/13
to robol...@googlegroups.com
This part of Android is totally messed up. I have no idea why they decided to make BluetoothDevice a final class but this is definitely really annoying. One solution I can think of is making a facade implementation that enables the customization and testing and using that instead of the BT classes in the application. Robolectric may have other means too, this is just a brute force solution.

Regards,
Andras


2013/1/15 Matt Wolfe <mwol...@gmail.com>
Reply all
Reply to author
Forward
0 new messages