首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

怎么进行Android单元测试

2012-06-30 
如何进行Android单元测试转自: http://www.cnblogs.com/feisky/archive/2010/07/23/1783826.html#Menifest

如何进行Android单元测试
转自: http://www.cnblogs.com/feisky/archive/2010/07/23/1783826.html
#
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="name.feisky.android.test"

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

热点排行