设置= Android Studio 2.3.3和Robolectric 2.4和gradle 3.2
我正在为AAAService类编写单元测试用例。以下是AAAService类。 但是,在调用HandlerThread类的quitSafely()时,会从测试文件中得到启发。
dput(l2)
list(a = structure(list(v1 = c(3L, 5L, 2L, 1L, 4L), v2 = c(8L,
6L, 7L, 5L, 4L)), class = "data.frame", row.names = c(NA, -5L
)), b = structure(list(v1 = c(9L, 18L, 17L, 5L, 13L), v2 = c(47L,
48L, 6L, 25L, 12L)), class = "data.frame", row.names = c(NA,
-5L)))
下面是单元测试文件。 onCreate()方法已成功执行,但是onDestry()在“ mAcsThread.quitSafely()”行中给出了例外;
public class AAAService extends Service {
private HandlerThread mAcsThread = null;
private Handler mSigHandler = null;
private Handler mCcsHandler = null;
private Handler mAcsHandler = null;
private Handler mDecoupledFunctionHandler = null;
public AAAService() {
}
public AAAService(Context context) {
mContext = context;
}
public void onCreate() {
mSigHandler = new Handler(mAcsThread.getLooper());
mCcsHandler = new Handler(mAcsThread.getLooper());
mAcsHandler = new Handler(mAcsThread.getLooper());
mDecoupledFunctionHandler = new Handler(mAcsThread.getLooper());
}
public void onDestroy() {
mAcsThread.quitSafely();
}
}
异常堆栈
@RunWith(RobolectricTestRunner.class)
public class AAAServiceTest {
@Test
public void onTest() throws Exception {
objAcsService.onCreate();
objAcsService.onDestroy();
}
}