qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

Android:单元测试Junit的配置

 在实际开发中,开发android软件的过程需要不断地进行测试。而使用Junit测试框架,侧是正规Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性..........

  第一步:首先在AndroidManifest.xml中加入下面代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="hb.learn.junit"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">

<!-- 在本应用中导入需要使用的包,放在application里面activity外面 -->
<uses-library android:name="android.test.runner" />

<activity android:name=".JunitTestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

<!-- 记住这个一要放在application外面,不然会出现配置错误 信息 -->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="hb.learn.junit" android:label="Tests for My App" />
</manifest>

  上面targetPackage指定的包要和应用的package相同。就是这个测试类所在的包名;

  第二步:编写单元测试代码(选择要测试的方法,右键点击“Run As”--“Android Junit Test” ):

import android.test.AndroidTestCase;
import android.util.Log;
public class XMLTest extends AndroidTestCase {
public void testSomething() throws Throwable {
Assert.assertTrue(1 + 1 == 3);
}
}


 在实际开发中,开发android软件的过程需要不断地进行测试。而使用Junit测试框架,侧是正规Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性..........

  第一步:首先在AndroidManifest.xml中加入下面代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="hb.learn.junit"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">

<!-- 在本应用中导入需要使用的包,放在application里面activity外面 -->
<uses-library android:name="android.test.runner" />

<activity android:name=".JunitTestActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

<!-- 记住这个一要放在application外面,不然会出现配置错误 信息 -->
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="hb.learn.junit" android:label="Tests for My App" />
</manifest>

  上面targetPackage指定的包要和应用的package相同。就是这个测试类所在的包名;

  第二步:编写单元测试代码(选择要测试的方法,右键点击“Run As”--“Android Junit Test” ):

import android.test.AndroidTestCase;
import android.util.Log;
public class XMLTest extends AndroidTestCase {
public void testSomething() throws Throwable {
Assert.assertTrue(1 + 1 == 3);
}
}

posted on 2013-08-02 11:46 顺其自然EVO 阅读(236) 评论(0)  编辑  收藏 所属分类: android


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年8月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜