我目前正在为Android应用程序编写单元测试,并偶然发现了以下问题:
我用它ServiceTestCase来测试IntentService这样的:
@Override
public void setUp() throws Exception {
super.setUp();
}
public void testService()
{
Intent intent = new Intent(getSystemContext(), MyIntentService.class);
super.startService(intent);
assertNotNull(getService());
}
Run Code Online (Sandbox Code Playgroud)
但是我注意到我IntentService的创建(意味着onCreate被调用),但我从未接到过调用onHandleIntent(Intent intent)
有人已经IntentService在ServiceTestCase课堂上测试了吗?
谢谢!
我一直在尝试IntentService使用Android提供的ServiceTestCase类来测试我,但测试失败了testServiceTestCaseSetUpProperly,首先失败了.我的代码如下:
public class MyClientServiceTest
extends ServiceTestCase<MyClientService> {
public static final String TAG = MyClientServiceTest.class.getName();
public static final String FILE_PREFIX = "test_";
private boolean bLoggingIn = false;
private boolean bLoggingOut = false;
private boolean bSendingScanRequest = false;
private boolean bGettingTemplates = false;
private final Class SERVICE_CLASS = MyClientService.class;
private RenamingDelegatingContext rdContext = null;
public MyClientServiceTest() {
super(MyClientService.class);
}
public MyClientServiceTest(Class<MyClientService> serviceType) {
super(MyClientService.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
rdContext = new …Run Code Online (Sandbox Code Playgroud)