Android test for ricardo leaked video, Android UI Test crashing on Android

Using MockK on Android UI tests should work the same on any emulator running Android 9+ as on a physical device.

On the simulator, tests that use MockK functions (as part of the test class file) mostly randomly fail with the following message:

Test run failed: Instruments run failed due to “Process Crashed”.

This so-called crash can happen before the first test starts or in the middle of a test sequence. Regardless of the test order, it’s fairly random.

Also, in rare cases, no crash occurs and all tests pass. But it’s too random here too.

In most cases, the reason for the crash will be printed in the log. Most of these are SIGENV, but the causes can vary and have no clear reason. Looking more closely at the logs, there seems to be an issue related to the InputDispatcher :

InputDispatcher: Channel ‘9fa7335’ ~ Channel is irreparably damaged and will be discarded!

Looking at SO for this message, it appears to be related to threading issues when manipulating activities that are not “activity”.

Unfortunately, I cannot provide code to reproduce the problem. However, I am using the MockK function in the MVP architecture as follows:

Check when you need to make sure a method is used
These tests also include Espresso View assertions to validate the displayed UI.

Please provide all relevant information about your setup. This is important if the problem cannot be reproduced under certain conditions.

MockK version: 1.10.0
Operating system: Windows 10
Kotlin version: 1.3.72′
JDK version: 1.8.0_242 released
JUnit version: 4.12
Test Type: Android Instrumentation Test