简体   繁体   中英

how to mock the Bluetooth adapter using any mocking Api for junit

I am trying to write junit test cases for my Bluetooth Code testing in android . My public method tries to call the buletooth adapter but its giving error like java.lang.RuntimeException: Method getDefaultAdapter in android.bluetooth.BluetoothAdapter not mocked.

any help would be highly appreciable.

BluetoothAdapter in the Android framework is declared final, so it cannot be mocked using Mockito or Robolectric. However, it is possible using PowerMock. Take a look at this example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM