久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Android 視圖中使用 UI 元素進行測試

Testing with UI elements in Android view(在 Android 視圖中使用 UI 元素進行測試)
本文介紹了在 Android 視圖中使用 UI 元素進行測試的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試使用以下測試用例測試簡單的 UI,主要思想是在測試中設置一些 UI 文本(模仿用戶輸入),然后主動點擊一個事件.

I am attempting to test simple UI with the following test case, The main idea is to set in the test some of the UI text (to mimic user input) and then actively click an event.

public class StackTestCase 
extends ActivityInstrumentationTestCase2<Stack> 
{
private StackDemo mActivity;

private EditText eaten;
    public StuckTestCase() {
         super("com.crocodil.software.stack", Stack.class);


    }
    public StuckTestCase(Class<Stack> activityClass) {
         super("com.crocodil.software.stack", activityClass);

    }
    protected void setUp() throws Exception {
        super.setUp();
        mActivity = this.getActivity();
        mCount = (Button) mActivity.findViewById(com.crocodil.software.stack.R.id.action);
        eaten = (EditText) mActivity.findViewById(com.crocodil.software.stack.R.id.eaten);

    }

    public void testPreconditions() {
        assertNotNull(mStatus);
      }

    public void testSimpleDefaults(){
        double status = Double.valueOf(mStatus.getText().toString());
        eaten.setText(2);
        mCount.performClick();
        assertEquals((status-2),Double.valueOf(mStatus.getText().toString()));
    }

}

運行結果是異常——

android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2802)
at android.view.ViewRoot.playSoundEffect(ViewRoot.java:2581)
at android.view.View.playSoundEffect(View.java:8516)
at android.view.View.performClick(View.java:2407)
at com.crocodil.software.stack.test.StackTestCase.testSimpleDefaults(StackTestCase.java:46)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

這發生在每次訪問 UI 元素時,我無法通過使用句柄或異步任務來避免它?有什么建議嗎?

This happens on each access to the UI elements and i was unable to avoid it by using handles or async task ? any suggestions?

推薦答案

這是一個老問題,但我還是給你一個答案,以防有人偶然發現.

This is an old question, but I'm giving you an answer anyway, in case someone stumbles upon it.

除了主線程(UI 線程)之外,您不能從任何地方更改 UI 小部件的狀態.您的 performClick 必須像這樣完成:

You are not allowed to change states of UI widgets from anywhere but the main thread (UI thread). Your performClick must be done like this:

mActivity.runOnUiThread(new Runnable() {
  @Override
  public void run() {
    mCount.performClick();
  }
});

但這還不是全部,您還需要通過添加以下行來將您的儀器測試與 ui 同步:

But that is not all, you will also need to sync your instrumentation test with the ui, by adding the following line:

getInstrumentation().waitForIdleSync();

同步行通常緊跟在 runOnUiThread() 代碼之后.

The sync line is usually placed immediately after the runOnUiThread() code.

這篇關于在 Android 視圖中使用 UI 元素進行測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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問題)
主站蜘蛛池模板: 日韩精品一区二区三区在线播放 | 国产精品久久久久久妇女 | 亚洲aⅴ | 精品国产乱码久久久久久影片 | 日韩超碰在线 | 日本免费在线观看视频 | 成人av播放 | 日韩三级精品 | 日韩三级| 日本超碰 | 天天拍天天色 | 亚洲综合五月天婷婷 | 国产一区二区电影网 | www性色| 在线国产欧美 | 97日韩精品| 国产精品日日摸夜夜添夜夜av | 中国一级特黄真人毛片 | 久久亚洲国产精品日日av夜夜 | 日韩视频在线一区二区 | 久久国产精品精品 | 亚洲欧美中文日韩在线v日本 | 国产精品美女一区二区 | 91av在线视频观看 | 国产丝袜一区二区三区免费视频 | av在线成人 | 伊人无码高清 | 狠狠操狠狠干 | 国产精品99久久久久久久久久久久 | jav成人av免费播放 | 色爱综合网 | 亚洲精品中文字幕在线 | 麻豆久久 | 日韩精品二区 | 国产99视频精品免费视频7 | 精品国产乱码久久久久久蜜臀 | 免费看黄色视屏 | 一级免费看 | 久久精品国产一区二区电影 | 福利视频二区 | 欧美成人黄色小说 |