[英]Android Integration Test: How to mock ClipData of intent of the onActivityResult using the Expresso intent
[英]Better Android Automated Test Performance using Expresso?
在研究了Android的自動測試框架之后,我偶然發現了Espresso。 它似乎擁有我想要的一切:可靠的測試,最少的樣板代碼,提高的性能。
我觀看了GTAC 2013演示中的Espresso演示,很高興看到它運行測試的速度。 然而,實際上已經實施了一些測試,我必須說,與使用標准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)));
}
我按照Espresso網站上的所有說明進行操作,並特別注意我的運行配置使用GoogleInstrumentationTestRunner。
那我想念什么呢? 我只是想念一些簡單的事情嗎? 還是我關於顯着提高性能的前提是完全錯誤的?
對於非常簡單的測試,您可能不會注意到它與標准儀器沒有太大的區別。 對於連續運行(即必須穩定)的更復雜的測試(例如,涵蓋多個活動的測試),人們通常最終會添加睡眠/重試邏輯以防止出現脆弱感。 使用Espresso,您可以刪除它並大大減少測試運行時間。 這是G +帖子 ,顯示了Espresso與Robotium測試的比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.