And*_*ega 5 java android servicetestcase
我正在尝试在android上构建一个有效的junit测试套件.
由于我是Junit的新手,我无法弄清楚如何使用ServiceTestCase类.
我无法弄清楚如何使getService()方法工作.它永远让我无效.所以我决定通过startService启动它.这是行不通的.
请你帮助我好吗 ?
谢谢
Die*_*ano 16
这是测试服务所需的
public class MyServiceTests extends ServiceTestCase<MyService> {
private static final String TAG = "MyServiceTests";
public MyServiceTests() {
super(MyService.class);
}
/**
* Test basic startup/shutdown of Service
*/
@SmallTest
public void testStartable() {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), MyService.class);
startService(startIntent);
assertNotNull(getService());
}
/**
* Test binding to service
*/
@MediumTest
public void testBindable() {
Intent startIntent = new Intent();
startIntent.setClass(getContext(), MyService.class);
IBinder service = bindService(startIntent);
assertNotNull(service);
}
}
Run Code Online (Sandbox Code Playgroud)
我写了一些关于Android测试和测试驱动开发的文章,你可能会发现它们很有用,请查看 http://dtmilano.blogspot.com/search/label/test%20driven%20development.