2

I was trying to achieve automation testing scenario using JUnit Framework of android. I used CountDownLatch as I wanted to include one asyncronous scenario.

I have written a testcase file using ServiceTestCase for my service. The service automatically starts an asynchronous operation using a thread. After doing async operation I get the result. This result i am trying to assert. Now if the operation is unsuccessful i try to do the async operation again. Now what is happening is the if operation is unsuccessful i try to redo the operation again in this case i am getting context as null.

Is it that when i start the service from testcase, After some time the context object becomes null? When is it garbage collected?

The service which i am using is a remote service. Is it creating a problem?

public class MyServiceTest extends ServiceTestCase<MyService>{
final CountDownLatch signal = new CountDownLatch(1);
Solo solo;
public MyServiceTest() {
    super(MyService.class);

}

public void testEndToEnd(){


    Intent intent = new Intent(MyService.class.getName());
    startService(intent);

    try {
        signal.await(60, TimeUnit.SECONDS);
    }
    catch(InterruptedException e) {
        e.printStackTrace();
    }

//want to put some assert statement
}    

}

In onCreate of service I am instantiate a Network class which will do heavy network operation. if the operation is failed send a broadcast notification. Now I have registered one BroadcastReceiver which will receive the notification and and restart the network operation. In this broadcastReciever i need the broadcast context which is coming null..

prolink007
  • 33,872
  • 24
  • 117
  • 185
Shrikanth Kalluraya
  • 1,099
  • 1
  • 16
  • 34

0 Answers0