lundi 6 juillet 2020

androidTest - Instrumented Android testing (Test depends on a Handler() object)

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

Aucun commentaire:

Enregistrer un commentaire