我的应用程序获取搜索结果并将其放在列表视图中,但我正在尝试测试它的结果。 这是搜索结果页面的截图。我的项目显示代码如下,以及我试图用来测试数据的代码。
final AlertDialog.Builder builder = new AlertDialog.Builder(SearchItemsActivity.this);
ListView listView = findViewById(R.id.listView);
listView.setAdapter(listViewAdapter);
onData(anything()).inAdapterView(withId(R.id.listView)).atPosition(1)
.check(matches(withText("Harry Potter Books - "+"In Stock"+"\n"+"Email: test12345@test.com\n"+"Full hardcover series\n")));
我得到的错误代码是
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "Harry Potter Books - In Stock\nEmail: test12345@test.com\nFull hardcover series\n"' doesn't match the selected view.
Expected: with text: is "Harry Potter Books - In Stock\nEmail: test12345@test.com\nFull hardcover series\n"
Got: "AppCompatTextView{id=16908308, res-name=text1, visibility=VISIBLE, width=1080, height=215, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.AbsListView$LayoutParams@ce20b7f, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Harry Potter Books - In Stock\nEmail: test12345@gmail.com\nFull hardcover series\n, input-type=0, ime-target=false, has-links=false}"