2014-01-28 42 views
6

我是新來的Espresso UI測試。Google Espresso java.lang.RuntimeException:無法啓動意圖Intent {act = android.intent.action.MAIN

我在運行測試時遇到此錯誤(ADT Eclipse IDE)。

該應用程序已經開發,並且在啓動應用程序時有很多請求正在進行。這是不可能的重寫應用程序。但是我需要找到測試這個用戶界面的方法,即使組件加載有任何延遲。

 java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.xx.android/com.yy.core.android.map.MapActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1390913271702 and and now the last time the queue went idle was: 1390913271767. If these numbers are the same your activity might be hogging the event queue. 
     at com.google.android.apps.common.testing.testrunner.GoogleInstrumentation.startActivitySync(GoogleInstrumentation.java:277) 
     at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119) 
     at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97) 
     at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104) 
     at com.gulesider.android.test.UItest.setUp(UItest.java:25) 
     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190) 
     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175) 
     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555) 
     at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167) 
     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1799) 
  1. 我有一個所謂的「核心」庫項目 - 它不會產生任何的apk
  2. 我也有一個叫做Android項目「AA」,將進入「核心」。 - 這是AA.apk
  3. 我現在已經創建了一個名爲「UItest」

清單測試項目:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.AA.android.test" 
     android:versionCode="1" 
     android:versionName="1.0" > 
    <uses-sdk android:minSdkVersion="8" 
      android:targetSdkVersion="18" /> 
    <instrumentation 
     android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" 
     android:targetPackage="com.AA.android"/> 
    <application 
      android:allowBackup="true" 
      android:icon="@drawable/ic_launcher" 
      android:label="@string/app_name" > 
    <activity 
       android:name="com.core.android.map.MapActivity" 
       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> 
    </manifest> 

我的測試:

public class UItest extends ActivityInstrumentationTestCase2<MapActivity> { 
     public UItest() { 
      super(MapActivity.class); 
     } 

     @Override 
     public void setUp() throws Exception { 
      super.setUp(); 

      getActivity(); 

     } 

     public void testSearchBox() { 

      Espresso.onView(ViewMatchers.withId(R.id.menu_button_logo)).perform(ViewActions.click()); 

     } 

    } 
+3

發佈你的代碼你做了什麼.. –

回答

0

在第一頁你會打電話太多的請求,這將花費超過15秒的時間,第一頁應該是非常輕的。 只需嘗試創建一個新的歡迎頁面,然後調用您的原始歡迎頁面。 希望爲你工作。

3

對於Espresso測試,強烈建議您關閉用於測試的虛擬或物理設備上的系統動畫。所以,你可以按照下面的步驟手動關閉動畫:

下: 設置 - >
開發者選項 - > 繪製

  1. 窗口動畫規模OFF
  2. 過渡動畫縮放到OFF
  3. 動畫時間刻度爲OFF
+0

我想知道如果有如果說明爲什麼這是發生和如何解決這個瓦特/ o關閉動畫 –

4

如果有一個進度條在你創建活動時運行,你會得到這樣的錯誤。您應該停止進度條以繼續運行測試。

+0

是的,這是正確的 - 可見的'ProgressBar'可能是這個例外的原因。檢查你的活動/片段是否沒有可見的ProgressBar(在ProgressBar中使用alpha時要小心) – xCh3Dx

1

在我的情況下,自定義視圖導致了這種行爲。它包含一個不斷滾動的Scroller。不幸的是,直到現在,我還沒有找到解決這個問題的方法,除了禁用它以進行測試...

+0

你是如何禁用它的? –

+0

我告訴View是一個自定義的視圖,當測試運行時不滾動。要確定它是否運行,我使用了以下解決方案:http://stackoverflow.com/a/28701836/3734116 –

2

我在6.0設備上運行Espresso測試但在5.1.1或7.0設備上運行時遇到此錯誤。我將原因追溯到在風格中使用android:fadeScrollbars。從我的樣式中刪除此項目解決了問題。

相關問題