lundi 28 décembre 2015

Android: PowerMockito Static JUnit Tests

I am currently writing Unit Tests for my bluetooth class.

Here is the method that I am currently on:

@VisibleForTesting
protected static Looper getConnectionTimeoutLooper() {
    HandlerThread handlerThread = new HandlerThread("BM-ConnectionTimeoutThread");
    handlerThread.start();
    return handlerThread.getLooper();
}

Here is what my Unit Test is looking like based on this StackOverflow post.

@Test
public void getConnectionTimeoutLooper_ReturnLooper() throws Exception {
    Looper mockLooper = mock(Looper.class);
    PowerMockito.mockStatic(BluetoothManager.class);
    BDDMockito.given(BluetoothManager.getConnectionTimeoutLooper()).willReturn(mockLooper);


    BluetoothManager.getConnectionTimeoutLooper();

    PowerMockito.verifyStatic();
    BluetoothManager.getConnectionTimeoutLooper();
}

I am now stumped. Please can someone assist me with this test.

Thanks

Aucun commentaire:

Enregistrer un commentaire