title: How to better unit test Looper and Handler code on Android?
body: <p>I use the android.os.Handler class to perform tasks on the background. When unit testing these, I call <code>Looper.loop()</code> to make the test thread wait for the background task thread to do its thing. Later, I call <code>Looper.myLooper().quit()</code> (also in the test thread), to allow the test thread to quit the <code>loop</code> and resume the testing logic.</p>
  
  <p>It's all fine and dandy until I want to write more than one test method.</p>
  
  <p>The problem is that Looper doesn't seem to be designed to allow quitting and restarting on the same thread, so I am forced to do all of my testing inside a single test method.</p>
  
  <p>I looked into the source code of Looper, and couldn't find a way around it.</p>
  
  <p>Is there any other way to test my Hander/Looper code? Or maybe some more test friendly way to write my background task class?</p>