Android测试基础整理篇Word格式文档下载.docx
- 文档编号:13898998
- 上传时间:2022-10-14
- 格式:DOCX
- 页数:15
- 大小:21.27KB
Android测试基础整理篇Word格式文档下载.docx
《Android测试基础整理篇Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Android测试基础整理篇Word格式文档下载.docx(15页珍藏版)》请在冰豆网上搜索。
lfail
2.自定义输出语句publicvoidtestMax(){
finalinta=1;
finalintb=2;
finalintexpected=b;
finalintactual=Math.max(a,b);
assertEquals("
Expection"
+expected+"
butwas"
+actual,expected,actual);
}3.控件Assertions
lassertBaselineAligned:
Assertsthattwoviewsarealignedontheirbaseline,thatistheirbaselinesareonthesameylocation.
lassertBottomAligned:
Assertsthattwoviewsarebottomaligned,thatistheirbottomedgesareonthesameylocation.
lassertGroupContains:
Assertsthatthespecifiedgroupcontainsaspecificchildonceandonlyonce.
lassertGroupIntegrity:
Assertsthespecifiedgroup'
sintegrity.Thechildrencountshouldbe&
gt;
=0andeachchildshouldbenon-null.
lassertGroupNotContains:
Assertsthatthespecifiedgroupdoesnotcontainaspecificchild.
lassertHasScreenCoordinates:
Assertsthataviewhasaparticularxandypositiononthevisiblescreen.
lassertHorizontalCenterAligned:
Assertsthatthetestviewishorizontallycenteralignedwithrespecttothereferenceview.
lassertLeftAligned:
Assertsthattwoviewsareleftaligned,thatistheirleftedgesareonthesamexlocation.Anoptionalmargincanalsobeprovided.
lassertOffScreenAbove:
Assertsthatthespecifiedviewisabovethevisiblescreen.
lassertOffScreenBelow:
Assertsthatthespecifiedviewisbelowthevisiblescreen.
lassertOnScreen:
Assertsthataviewisonthescreen.
lassertRightAligned:
Assertsthattwoviewsareright-aligned,thatistheirrightedgesareonthesamexlocation.Anoptionalmargincanalsobespecified.
lassertTopAligned:
Assertsthattwoviewsaretop-aligned,thatistheirtopedgesareonthesameylocation.Anoptionalmargincanalsobespecified.
lassertVerticalCenterAligned:
Assertsthatthetestviewisverticallycenteralignedwithrespecttothereferenceview.
4.TouchUtils
lClickingonaViewandreleasingit
lTappingonaView,thatistouchingitandquicklyreleasing
lLongclickingonaView
lDraggingthescreen
publicvoidtestListScrolling(){
mListView.scrollTo(0,0);
TouchUtils.dragQuarterScreenUp(this,mActivity);
TouchUtils.tapView(this,mListView);
finalintexpectedItemPosition=6;
finalintactualItemPosition=
mListView.getFirstVisiblePosition();
assertEquals("
Wrongposition"
expectedItemPosition,actualItemPosition);
finalStringexpected="
Anguilla"
;
finalStringactual=mListView.getAdapter().
getItem(expectedItemPosition).toString();
Wrongcontent"
actual,expected);
}
5.Mock对象
lMockApplication:
AmockimplementationoftheApplicationclass.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockContentProvider:
AmockimplementationofContentProvider.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockContentResolver:
AmockimplementationoftheContentResolverclassthatisolatesthetestcodefromtherealcontentsystem.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockContext:
AmockContextclass.Thiscanbeusedtoinjectotherdependencies.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockCursor:
AmockCursorclassthatisolatesthetestcodefromrealCursorimplementation.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockDialogInterface:
AmockimplementationofDialogInterfaceclass.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockPackageManager:
AmockimplementationofPackageManagerclass.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
lMockResources:
AmockResourcesclass.Allmethodsarenon-functionalandthrowUnsupportedOperationException.
2.框架结构
1AndroidTestCase
当你需要用到ActivityContext的时候就使用这个类,比如Resources,database,filesystem,你可以是用mContext来是用context。
你可以用ontext.startActivity()来启动多个Activity。
有很多个testcase继承自这个类:
lApplicationTestCase&
lt;
TextendsApplication&
lProviderTestCase2&
TextendsContentProvider&
lServiceTestCase&
TextendsService&
2Instrumentation
这个是用来监视Activity和Application的,你可以用它来控制Activity的生命周期和用户交互事件。
l我们可以是用Instrumentation.ActivityMonitor来监测一个Activity。
例如:
publicvoidtestFollowLink(){
finalInstrumentationinst=getInstrumentation();
IntentFilterintentFilter=newIntentFilter(Intent.ACTION_VIEW);
intentFilter.addDataScheme("
http"
);
intentFilter.addCategory(Intent.CATEGORY_BROWSABLE);
ActivityMonitormonitor=inst.addMonitor(
IntentFilter,null,false);
assertEquals(0,monit
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 测试 基础 整理
![提示](https://static.bdocx.com/images/bang_tan.gif)