Android JUnit单元测试
16lz
2021-01-23
Android下的单元测试不能像以前的java项目进行JUnit测试,必须在配置文件中添加两个东西:(黑色背景文字)
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wuyou.wuyoumessagesender" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.wuyou.wuyoumsgsender" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <uses-library android:name="android.test.runner" /> </application></manifest>
其中targetPackage要填写测试的包。
测试的类必须继承AndroidTestCase类:
import junit.framework.Assert;import com.wuyou.layouttest.AddService;import android.test.AndroidTestCase;public class Test extends AndroidTestCase { public void testAdd() { AddService addService = new AddService(); int result = addService.add(1, 2); Assert.assertEquals(4, result); }}
怎样获取xml下面的两句话呢?
原来在eclipse下面可以添加一个项目(project),选择android test project条目,创建一个项目,在该项目下的manifest的xml文件就有这两项内容。
更多相关文章
- android-单元测试(Android JUnit Test)
- zxing项目源码解读(2.3.0版本,Android部分)
- 【android】Android Studio项目打包,发布APK
- Tiny210(Android)串口收发测试通过
- Android Studio快捷键、配置 Android Studio、cmake配置Android
- 搭建android测试环境
- android原生项目整合ReactNative
- 【Android 应用开发】GitHub 优秀的 Android 开源项目
- Android Q 测试版