Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to get this working using the procedure below..anyone is welcome to chime in if this is incorrect, but the example above works (i.e. MyBindServer's handler receives messages)</p> <p>It seems as though ServiceTestCase's bindService() method intends to act like a local service. In this case, the goal is to test as a separate process, which means using the following instead of ServiceTestCase's bindService:</p> <pre><code>Intent bindIntent = new Intent(&lt;registered intent&gt;); //Where registered intent is declared in the manifest file getContext().bindService(bindIntent,mConn,Context.BIND_AUTO_CREATE); </code></pre> <p>where mConn is a ServiceConnection object implemented to do whatever your test needs it to do, in the case above, set mServer.</p> <p>With the above, MyBindServer's handleMessage() is called for the testAHello() test.</p> <p>UPDATE: I have noticed that depending on how quickly the test processing is done, teardown() can be called before the binding is ready to use. In the case above adding control variables to throttle the program flow based on mConn's onServiceConnected being called provided consistent results.</p> <p>E.g.</p> <pre><code>protected boolean bound = false; protected boolean processed = false; private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { Log.i(TAG,"Service conn"); mServer = new Messenger(service); if(mServer != null &amp;&amp; mServer != null){ bound = true; } processed = true; } @Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub Log.i(TAG,"Service Disconn"); } }; </code></pre> <p>Then add:</p> <pre><code>while(!processed){ try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>to testAHello()</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload