Wednesday, 11 September 2013

NullpointerException when stopService in ServiceTestCase

NullpointerException when stopService in ServiceTestCase

I am testing my service by using ServiceTestCase.
public class MyTest extends ServiceTestCase<MyService>{
private Context mContext;
private Intent intent;
public MyTest(){
super(MyService.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
mContext = this.getContext();
intent = new Intent(mContext, MyService.class);
}
@MediumTest
public void runMyTest(){
startService(intent);
}
@Override
public void tearDown() throws Exception {
super.tearDown();
MyService service = getService();
mContext.stopService(intent); //NullpointerException here
}
But when I run my test, I constantly get NullPointerException when call
stopService(intent) in tearDwon() callback. Why?

No comments:

Post a Comment