如何进行Android单元测试
外面加入:
MISSION android:name="android.permission.RUN_INSTRUMENTATION" />
android:label="Test for my app"/>
编写单元测试代码:必须继承自AndroidTestCase类
package name.feisky.android.test;
import android.test.AndroidTestCase;
import junit.framework.Assert;
public class MyTest extends AndroidTestCase {
private static final String Tag="MyTest";
public void testSave() throws Throwable
{
int i=4+8;
Assert.assertEquals(5,i);
}
public void testSomethingElse() throws Throwable {
Assert.assertTrue(1 + 1 == 12);
}
}
执行测试
IntelliJ中:
eclipse中:右键 run as Android JUnit Test
命令行工具:
adb shell am instrument -w name.feisky.android.test/android.test.InstrumentationTestRunner
也可以新建一个测试项目进行测试
New > Project > Android > Android Test Project.