During many of my tests, my app is running AsyncTasks
that access the database and cannot be cancelled. At the end of my tests, I close my database, delete it, then reopen it so I have a fresh database fixture.
The problem is that when the AsyncTasks
happen to still be running during the time when the test is closing and deleting the database, I'll get a runtime exception in the code. This couldn't ever happen in the production code because the database is never closed in production.
Robotium has a test helper method called finishOpenedActivities
that I use in my test teardown method. If there were some way to modify the finishOpenedActivities to ensure that all child threads (AsyncTasks specifically) were finished as well, that would be tremendously helpful. Otherwise I probably have to go implement checks for cancelled in all my AsyncTasks just to support reliable testing.
Is there were some way to wait until all child threads (AsyncTasks specifically) are finished?