현재 으로 에스프레소로 android에서 ListView
을 테스트하려고합니다. listActivity.addAssociation(association);
단순히 associationArrayAdapter.add(association);
않습니다Android 에스프레소 - ListView 행 테스트
final AssociationsListActivity listActivity = getActivity();
final Association association1 = new Association(ASSOCIATION_NAMES[0], ASSOCIATION_DESCRIPTIONS[0]);
final Association association2 = new Association(ASSOCIATION_NAMES[1], ASSOCIATION_DESCRIPTIONS[1]);
final Association association3 = new Association(ASSOCIATION_NAMES[2], ASSOCIATION_DESCRIPTIONS[2]);
listActivity.addAssociation(association1);
listActivity.addAssociation(association2);
listActivity.addAssociation(association3);
assertTrue(listActivity.getAssociationsList().size() == 3);
onView(withId(R.id.associationsListView)).check(matches(isDisplayed()));
onData(anything())
.inAdapterView(withId(R.id.associationsListView))
.atPosition(0)
.perform(click());
assertCurrentActivityIsInstanceOf(AssociationsListActivityTest.this
, AssociationsPageActivity.class);
방법 : 다음은 테스트입니다. ArrayAdapter
는 ID와 ListView
(기본적으로 표시)에 요소를 추가하는 데 사용됩니다 R.id.associationsListView
나는이 테스트를 실행할 때, 나는 다음과 같은 오류 얻을 :
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "ListView{id=2131427414, res-name=associationsListView, visibility=VISIBLE, width=996, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=42.0, y=42.0, child-count=0}"
에 의해 발생 이 주장을 주석 할 때 다음과 같은 주장, 또한 onView(withId(R.id.associationsListView)).check(matches(isDisplayed()));
, 다음 하나는 다음과 같은 예외가 발생합니다
android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'with id: ch.epfl.sweng.project:id/associationsListView'.
...
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
(is assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "ListView{id=2131427414, res-name=associationsListView, visibility=VISIBLE, width=996, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=42.0, y=42.0, child-count=0}"
이러한 예외를 다루는 스택 오버플로 스레드를 많이 겪었으므로 이러한 테스트를 다른 동등한 방법으로 대체했지만 이러한 오류는 여전히 무엇을해야할지 모르겠다! 어떤 도움을 주셔서 감사합니다!