0

Now I'm busy testing some classes which are related to the BLE functionality. Therefore, I wrote some instrumented tests. There is one class that depends on a Handler() object. It's difficult to test more than one function because I'm using now Looper.prepare() inside one test, so that the class which I want to test is initialized without exceptions. If I want to write a second test it fails because of the Looper. I get the following exception:

java.lang.RuntimeException: Only one Looper may be created per thread.

I also noticed that there is an order for the tests. Do you know what it depends on? The test: iniRepositoryTest() is excuted before checkIfProductConfiguredTest(). If I use Looper.prepare() only in initRepositoryTest() both tests run without exception.

PS: I know the test names could be better :D

1 Answers1

0

I've managed to get rid of that error by using the @UiThreadTest annotation. Give it a try.

Or try this if you need a Handler: https://stackoverflow.com/a/53933984

Nuno
  • 76
  • 3