Shahnawaz Jafri
Shahnawaz Jafri

Reputation: 115

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.

Upvotes: 4

Views: 5382

Answers (1)

SoroushA
SoroushA

Reputation: 2121

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.

Upvotes: 0

Related Questions