新建测试类ApiTest
publicclassApiTestextendsServiceTestCase<SecurityService> {
publicApiTest() {
super(SecurityService.class);
}
protectedvoidsetUp()throwsException {
Log.e(getName(),"setUp...");
super.setUp();
}
protectedvoidteardown()throwsException {
Log.e(getName(),"tearDown...");
super.tearDown();
}
/**
* Test bind service
*/
publicvoidtestBindable() {
Intent startIntent =newIntent();
startIntent.setClass(getSystemContext(), SecurityService.class);
IBinder service = bindService(startIntent);
assertEquals(true, service.isBinderAlive());
}
/**
* Test getAgentVersionCode
*/
publicvoidtestGetAgentVersionCode() {
Intent startIntent =newIntent();
startIntent.setClass(getSystemContext(), SecurityService.class);
IBinder service = bindService(startIntent);
if(service.isBinderAlive()) {
SecurityAgent securityAgent = SecurityAgent.Stub
.asInterface(service);
intversionCode = 0;
try{
versionCode = securityAgent.getAgentVersionCode();
}catch(RemoteException e) {
//TODOAuto-generated catch block
e.printStackTrace();
}
assertEquals(2, versionCode);
}
}
}
使用与被测应用相同签名编译安装测试apk,即可运行测试了。