本代码中只简单写了一个类,可以在该类中增加想要测试的功能项。 Focus2AndroidTest测试类 package com.example.aaaaa; i
本代码中只简单写了一个类,可以在该类中增加想要测试的功能项。
Focus2AndroidTest测试类 package com.example.aaaaa; import android.test.AndroidTestCase; public class Focus2AndroidTest extends AndroidTestCase { @Override protected void setUp() throws Exception { // TODO Auto-generated method stub super.setUp(); System.out.println("====aaaa===="); } }
AndroidManifest.xml中需要增加几个属性
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=Http://schemas.android.com/apk/res/android package="com.example.aaaaa" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.aaaaa.Focus2AndroidTest" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MaiN" /> <cateGory android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <uses-library android:name="android.test.runner" />//增加的第一个位置 </application> <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" />//增加的第二个位置 <instrumentation android:name="android.test.InstrumentationTestRunner" android:label="Test for my app" android:targetPackage="com.example.aaaaa" /> </manifest>
运行程序时与正常的运行部太一样。右键功工程名->run as->android jUnit test即可看到运行结果。
注意包名等地方要与当前工程名相一致。
运行结果:(右侧的东西为正常运行后的内容)
--结束END--
本文标题: Android 单元测试用法 简介
本文链接: https://www.lsjlt.com/news/28620.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0