YT Advanced Android Espresso cihazında harika bir enstrümantal test eğiticisi buldum. İhtiyaçlarıma küçük ayarlarla oradan kodu aldım.Android enstrümantal testinde Araç çubuğu başlığı nasıl kontrol edilir?
import static android.support.test.InstrumentationRegistry.getInstrumentation;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.AllOf.allOf;
...
@Test
public void checkToolbarTitle() {
String toolbarTitile = getInstrumentation().getTargetContext().getString(R.string.my_bus_stops);
onView(allOf(isAssignableFrom(TextView.class), withParent(isAssignableFrom(Toolbar.class)))).check(matches(withText(toolbarTitile)));
}
Maalesef benim için çalışmaz. Test başarısız oldu:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (is assignable from class: class android.widget.TextView and has parent matching: is assignable from class: class android.widget.Toolbar)
Sorun nedir? Bunu başka şekilde nasıl test edebilirim?
Bu benim için çalışmadı. Grzegorz Bielanski'nin gönderdiği gibi ithalat oldu. Örneğin, benim için çözümlenemedi. –
Sadece neden aşağı oylama merak ediyorsun ?! Vakaların çoğunda (oy miktarına bakınız) çalışır ve sizin için işe yaramadığı gerçeği bu cevabı yanlış yapmaz. – denys
"Çoğu durumda" için çalıştığını nasıl anlarım? Deneyimlerim, Android'de çalışanların sürümden sürüme değişmesi ve bugün alakalı bir cevabın yarın alakalı olduğundan emin olmaması. –