首页 > 移动平台 > 详细

Android开发基础之Android Studio单元测试

时间:2015-03-06 12:43:10      阅读:259      评论:0      收藏:0      [点我收藏+]
android studio默认支持单元测试,相对于Eclipse要方便一些。
新建完一个项目之后你会发现同时生成了一个ApplicationTest类,如图:
技术分享


同样,假设已经实现了一个计算百分比功能需要测试,代码:
public class ProgressService {  
    public Integer getCurrentProgerss(double current, double max) {  
        Integer i=(int)((current / max) * 100) ;  
        return i;  
    }  
}  

具体步骤如下:


一 测试类

在ApplicationTest包中新建一个测试类,来执行我们的功能,这个类需要继承InstrumentationTestCase。
import android.test.InstrumentationTestCase;
public class TestClass extends InstrumentationTestCase {
    public void test() throws Exception{
        ProgressService progressService=new ProgressService();  
        Integer pro=progressService.getCurrentProgerss(20, 70);  
        Log.i(TAG, pro.toString()); 
    }
}

二 运行

选中刚刚新建的测试类TestClass,右键->run->TestClass,如图:

技术分享

Android开发基础之Android Studio单元测试

原文:http://blog.csdn.net/xufeng0991/article/details/44098091

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!