2014-01-28 28 views
0

研究Android自動化測試框架後,我偶然發現了Espresso。它似乎擁有我想要的一切:可靠的測試,最少的樣板代碼,更高的性能。使用Expresso更好的Android自動化測試性能?

我觀看了演示Espresso的GTAC 2013演示文稿,很高興看到它運行測試的速度。但是,實際上已經實現了一些測試,但我必須說,如果有任何性能優於使用標準Android測試框架,我不會注意太多。我還沒有做過任何「官方」基準測試,但我的理解是,Espresso吹掉了標準的Android測試框架。

我正在測試的項目是在developer.android.com上的教程中描述的項目。那我寫的測試是非常簡單的:

@Test 
public void test_sendButton_shouldInitiallyBeDisabled() { 
    onView(withId(R.id.button_send)).check(matches(not(ViewMatchers.isEnabled()))); 
} 

@Test 
public void test_sendButton_shouldBeEnabledAfterEnteringText() { 
    String enteredText = "This is my message!"; 
    // Type Text 
    onView(withId(R.id.edit_message)).perform(ViewActions.typeText(enteredText)); 

    // Validate the Result 
    onView(withId(R.id.button_send)).check(matches(ViewMatchers.isEnabled())); 
} 

@Test 
public void test_enteringTextAndPressingSendButton_shouldDisplayEnteredText() { 
    String enteredText = "This is my message!"; 
    // Type Text 
    onView(withId(R.id.edit_message)).perform(ViewActions.typeText(enteredText)); 

    // Click Button 
    onView(withId(R.id.button_send)).perform(click()); 

    // Validate the Results 
    onView(withId(R.id.display_message)).check(ViewAssertions.matches(ViewMatchers.withText(enteredText))); 
} 

我跟着咖啡網站上的所有指令,支付特別是我的運行配置中使用的GoogleInstrumentationTestRunner密切關注。

那麼我錯過了什麼?我錯過了簡單的事情嗎?或者,我的前提是完全錯誤地改進了性能?

回答

3

事實上,對於非常簡單的測試,您沒有發現與標準儀器相比有很大差異。對於連續運行(即必須穩定)的更復雜的測試(例如跨越多個活動的測試),人們通常最終會添加睡眠/重試邏輯以防止出現輕微滑動。藉助Espresso,您可以將其刪除,並大大減少測試運行時間。這是一個G+ post,它顯示了Espresso與Robotium測試的對比。