pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何跨多個活動測試 Android 應用程序?

How do you test an Android application across multiple Activities?(如何跨多個活動測試 Android 應用程序?)
本文介紹了如何跨多個活動測試 Android 應用程序?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我們正在構建一個復雜的 Android 應用程序,該應用程序由分布在許多活動中的許多屏幕和工作流組成.我們的工作流程類似于您在銀行的 ATM 機上看到的工作流程,例如,有一個 Activity 可以登錄,轉換到主菜單 Activity 可以轉換到基于用戶選擇的其他活動.

We are building a complex Android application consisting of many screens and workflows spread across many Activities. Our workflows are similar to what you might see on a Bank's ATM machine, for example, there is an Activity to login in that transitions to a main menu Activity which can transition to other activities based on the user's choices.

由于我們有如此多的工作流程,我們需要創建跨越多個活動的自動化測試,以便我們可以端到端地測試工作流程.例如,使用 ATM 示例,我們想輸入一個有效的 PIN,驗證將我們發送到主菜單,選擇提取現金,驗證我們是否在提取現金屏幕上等等,最終找到自己返回主菜單或退出".

Since we have so many workflows we need to create automated tests that span multiple activities so we can test a workflow from end to end. For example, using the ATM example, we would want to enter a valid PIN, verify that sends us to the main menu, choose withdraw cash, verify that we are on the withdraw cash screen, etc., etc., and eventually find ourselves back on the main menu or "logged" out.

我們玩弄了 Android 附帶的測試 API(例如 ActivityInstrumentationTestCase2)以及 Positron,但似乎都無法測試超出單個 Activity 的范圍,雖然我們可以在這些工具中找到一些實用程序來進行某些單元測試,但它們不會無法滿足我們對跨越多個活動的測試場景的需求.

We've toyed with the test APIs that come with Android (e.g. ActivityInstrumentationTestCase2) and also with Positron, but neither seem capable of testing beyond the bounds of a single Activity, and while we can find some utility in these tools for some unit testing, they won't meet our needs for testing scenarios that cut across multiple Activities.

我們對 xUnit 框架、腳本、GUI 記錄器/回放等持開放態度,并希望得到任何建議.

We are open to an xUnit framework, scripting, GUI recorders/playbacks, etc. and would appreciate any advice.

推薦答案

回答我自己的懸賞問題有點尷尬,但這里是......

I feel a bit awkward about answering my own bounty question, but here it is...

我對此進行了高低搜索,無法相信任何地方都沒有發布答案.我已經非常接近了.我現在絕對可以運行跨越活動的測試,但我的實現似乎有一些時間問題,測試并不總是可靠地通過.這是我所知道的成功跨多個活動進行測試的唯一示例.希望我對它的提取和匿名化不會引入錯誤.這是一個簡單的測試,我在登錄活動中輸入用戶名和密碼,然后觀察在不同的歡迎"活動中顯示正確的歡迎消息:

I've searched high and low on this and can't believe there is no answer published anywhere. I have come very close. I can definitely run tests that span activities now, but my implementation seems to have some timing issues where the tests don't always pass reliably. This is the only example that I know of that tests across multiple activities successfully. Hopefully my extraction and anonymizing of it did not introduce errors. This is a simplistic test where I type a username and password into a login activity, and then observe a proper welcome message is shown on a different "welcome" activity:

package com.mycompany;

import android.app.*;
import android.content.*;
import android.test.*;
import android.test.suitebuilder.annotation.*;
import android.util.*;
import android.view.*;
import android.widget.*;

import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.*;
import static com.mycompany.R.id.*;

public class LoginTests extends InstrumentationTestCase {

   @MediumTest
   public void testAValidUserCanLogIn() {

      Instrumentation instrumentation = getInstrumentation();

      // Register we are interested in the authentication activiry...
      Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(AuthenticateActivity.class.getName(), null, false);

      // Start the authentication activity as the first activity...
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setClassName(instrumentation.getTargetContext(), AuthenticateActivity.class.getName());
      instrumentation.startActivitySync(intent);

      // Wait for it to start...
      Activity currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
      assertThat(currentActivity, is(notNullValue()));

      // Type into the username field...
      View currentView = currentActivity.findViewById(username_field);
      assertThat(currentView, is(notNullValue()));
      assertThat(currentView, instanceOf(EditText.class));
      TouchUtils.clickView(this, currentView);
      instrumentation.sendStringSync("MyUsername");

      // Type into the password field...
      currentView = currentActivity.findViewById(password_field);
      assertThat(currentView, is(notNullValue()));
      assertThat(currentView, instanceOf(EditText.class));
      TouchUtils.clickView(this, currentView);
      instrumentation.sendStringSync("MyPassword");

      // Register we are interested in the welcome activity...
      // this has to be done before we do something that will send us to that
      // activity...
      instrumentation.removeMonitor(monitor);
      monitor = instrumentation.addMonitor(WelcomeActivity.class.getName(), null, false);

      // Click the login button...
      currentView = currentActivity.findViewById(login_button;
      assertThat(currentView, is(notNullValue()));
      assertThat(currentView, instanceOf(Button.class));
      TouchUtils.clickView(this, currentView);

      // Wait for the welcome page to start...
      currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 5);
      assertThat(currentActivity, is(notNullValue()));

      // Make sure we are logged in...
      currentView = currentActivity.findViewById(welcome_message);
      assertThat(currentView, is(notNullValue()));
      assertThat(currentView, instanceOf(TextView.class));
      assertThat(((TextView)currentView).getText().toString(), is("Welcome, MyUsername!"));
   }
}

這段代碼顯然不是很可讀.我實際上已經將它提取到一個帶有類似英語 API 的簡單庫中,所以我可以這樣說:

This code is obviously not very readable. I have actually extracted it into a simple library with an English-like API so I can just say things like this:

type("myUsername").intoThe(username_field);
click(login_button);

我已經對大約 4 項活動進行了深度測試,并且對這種方法的工作感到滿意,盡管正如我所說,似乎偶爾會出現一個我還沒有完全弄清楚的時間問題.我仍然有興趣了解跨活動的任何其他測試方式.

I've tested to a depth of about 4 activities and am satisfied that the approach works though as I said, there appears to be an occasional timing issue I have not completely figured out. I am still interested in hearing of any other ways of testing across activities.

這篇關于如何跨多個活動測試 Android 應用程序?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 电动葫芦-河北悍象起重机械有限公司 | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 伺服电机维修、驱动器维修「安川|三菱|松下」伺服维修公司-深圳华创益 | 防火板_饰面耐火板价格、厂家_品牌认准格林雅 | 大型果蔬切片机-水果冬瓜削皮机-洗菜机切菜机-肇庆市凤翔餐饮设备有限公司 | 浙江皓格药业有限公司| 乳化沥青设备_改性沥青设备_沥青加温罐_德州市昊通路桥工程有限公司 | 大巴租车平台承接包车,通勤班车,巴士租赁业务 - 鸿鸣巴士 | 济南宣传册设计-画册设计_济南莫都品牌设计公司| 机房监控|动环监控|动力环境监控系统方案产品定制厂家 - 迈世OMARA | 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 渣油泵,KCB齿轮泵,不锈钢齿轮泵,重油泵,煤焦油泵,泊头市泰邦泵阀制造有限公司 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 杜康白酒加盟_杜康酒代理_杜康酒招商加盟官网_杜康酒厂加盟总代理—杜康酒神全国运营中心 | 商标转让-商标注册-商标查询-软著专利服务平台 - 赣江万网 | 振动台-振动试验台-振动冲击台-广东剑乔试验设备有限公司 | 洛阳网站建设_洛阳网站优化_网站建设平台_洛阳香河网络科技有限公司 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 臭氧实验装置_实验室臭氧发生器-北京同林臭氧装置网 | FAG轴承,苏州FAG轴承,德国FAG轴承-恩梯必传动设备(苏州)有限公司 | 杭州ROHS检测仪-XRF测试仪价格-百科 | 商标转让-购买商标专业|放心的商标交易网-蜀易标商标网 | 热处理炉-退火炉-回火炉设备厂家-丹阳市电炉厂有限公司 | 全自动不干胶贴标机_套标机-上海今昂贴标机生产厂家 | 飞歌臭氧发生器厂家_水处理臭氧发生器_十大臭氧消毒机品牌 | 美侍宠物-专注宠物狗及宠物猫训练|喂养|医疗|繁育|品种|价格 | 成都治疗尖锐湿疣比较好的医院-成都治疗尖锐湿疣那家医院好-成都西南皮肤病医院 | 垃圾压缩设备_垃圾处理设备_智能移动式垃圾压缩设备--山东明莱环保设备有限公司 | 硫化罐-电加热蒸汽硫化罐生产厂家-山东鑫泰鑫智能装备有限公司 | PE拉伸缠绕膜,拉伸缠绕膜厂家,纳米缠绕膜-山东凯祥包装 | 南京办公用品网-办公文具用品批发-打印机耗材采购 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | 微型驱动系统解决方案-深圳市兆威机电股份有限公司 | 防火卷帘门价格-聊城一维工贸特级防火卷帘门厂家▲ | 广州昊至泉水上乐园设备有限公司| Q361F全焊接球阀,200X减压稳压阀,ZJHP气动单座调节阀-上海戎钛 | 上海道勤塑化有限公司| 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 耙式干燥机_真空耙式干燥机厂家-无锡鹏茂化工装备有限公司 | (中山|佛山|江门)环氧地坪漆,停车场地板漆,车库地板漆,聚氨酯地板漆-中山永旺地坪漆厂家 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 |