KEY:Android JUnit Android单元测试 单元测试
Menifest.xml中加入:
<application>中加入:
<uses-library android:name="android.test.runner" />
<application>外面加入:
<uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.***.***【您的项目包名】"
android:label="JUnit Test"/>
编写单元测试代码:必须继承自AndroidTestCase类
import android.test.AndroidTestCase;
import junit.framework.Assert;
public class JUnitTest extends AndroidTestCase {
private static final String Tag="JUnitTest";
public void testOne() throws Throwable
{
int i=1 + 1;
Assert.assertEquals(2,i);
}
public void testOther() throws Throwable {
Assert.assertTrue(1 + 1 == 12);
}
}
Eclipse下选择运行>>Android JUnit Test ,就OK了