使用ServiceTestCase进行Android的Service类型API测试(二)

上一篇 / 下一篇  2012-05-15 17:26:08 / 个人分类:Android测试

新建测试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,即可运行测试了。


TAG:

 

评分:0

我来说两句

Open Toolbar