我有一个以IntentService
开始的类:
public class MyClass(){
public void doStuff(){
Intent intent = new Intent(context, MyService.class);
intent.putExtra(KEY, stringExtra);
context.startService(intent);
}
}
现在,我想进行单元测试的是
MyClass
类。我希望检查启动我的服务的意图是否已经触发,并且它具有正确的附加信息。像这样:public void testServiceStarted(){
MyClass myClass = new MyClass();
myClass.doStuff();
// Assert MyService was stated and received arguments
}
这是否可能通过Instrumentation或其他框架实现?