ActivityMonitor gets hit, but getLastActivity returns null

I have a problem with one of the test cases in my test suite. What I'm trying to do is just click on the button and wait for a new action to start.

ActivityMonitor monitor = getInstrumentation().addMonitor(MyActivity.class.getName(), null, false); TouchUtils.clickView(this, searchButton); Activity a = getInstrumentation().waitForMonitorWithTimeout(monitor, 60); assertNotNull("The MyActivity is null.", a); 

This code must, in accordance with the documentation, wait up to 60 seconds for the monitor to hit. If it hits, the operation will be returned (and null otherwise).

What happens is that the test passes from time to time, but most of the time it fails because a == null . I watch the test when it works, and I clearly see that it does not wait 60 seconds. Only a few. With some printing findings, I also noticed that the monitor actually hits, but the activity returned by getLastActivity() still null .

1) How is this possible?

2) And is there something I can do to avoid this?

+4
source share

Source: https://habr.com/ru/post/1439118/


All Articles