public class ProgressService {
public Integer getCurrentProgerss(double current, double max) {
Integer i=(int)((current / max) * 100) ;
return i;
}
}要对指定功能进行单元测试,详细步骤如下:
编写一个测试类,来执行我们的功能,这个类需要继承AndroidTestCase。
import android.test.AndroidTestCase;
import android.util.Log;
import com.example.service.ProgressService;
public class ProgressServiceJUnit extends AndroidTestCase {
private final String TAG="main";
public ProgressServiceJUnit() {
// TODO Auto-generated constructor stub
}
public void getCurrentProgerssTest(){
ProgressService progressService=new ProgressService();
Integer pro=progressService.getCurrentProgerss(20, 70);
Log.i(TAG, pro.toString());
}
}<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> 添加权限 <instrumentation android:name="android.test.InstrumentationTestRunner" 固定类容 android:targetPackage="com.example.junittestdemo" > 要测试功能所在的包 </instrumentation>
<application> ... <uses-library android:name="android.test.runner" /> ... <application/>
原文地址:http://blog.csdn.net/xufeng0991/article/details/44097943