Android应用程序的调试方法
16lz
2021-01-23
Android有时候我们需要调试或者测试一个类是否正确,我们可以使用如下方法。以下面的程序为例,我们测试下面的Person类是否正确。
package com.heima.junit;public class Person {public void eat() {System.out.println("eat ....");}public int divide(int i, int j) {return i/j;}}
我们很容易看出Person类的divide()成员方法的第二个参数不能为0,假设我们不知道。 第一步:写个类去继承 AndroidTestCase 类
package test;import com.heima.junit.Person;import android.test.AndroidTestCase;public class testPerson extends AndroidTestCase {public void test1() {Person p = new Person();p.eat();System.out.println(p.divide(2, 1));}public void test2() {Person p = new Person();p.eat();System.out.println(p.divide(2, 0));}}
第二步:清单文件manifest中, 添加instrumentation 指令集
第三步:继续在清单 文件application中,添加 uses-library
<?xml version="1.0" encoding="utf-8"?>
按以下方法执行:
更多相关文章
- 详解Android获取系统内核版本的方法与实现代码
- Android Studio项目应该提交哪些文件到GitHub上
- Android下文件操作模式(含SDCard的读写)
- JNI基础实验一:调用.so文件--友善之臂Tiny210 android 串口/pwm/A
- Android模拟用户点击的实现方法