如何测试搜索结果?

时间:2017-03-11 14:36:29

标签: android android-espresso

测试步骤:

  1. 输入要搜索的文字
  2. 测试输入文本是否显示在列表中
  3. 我的测试:

    private static final String TEST_SURNAME = "AnySurname";
    private static final String TEST_NAME = "AnyName";
    private static final String TEST_FULL_NAME = TEST_SURNAME + " " + TEST_NAME;
    
    @Test
    public void searchTestPerson() {
         onView(withId(R.id.searchView)).perform(click());
         onView(withId(android.support.design.R.id.search_src_text)).perform(typeText(TEST_FULL_NAME));
         onData(allOf(withRowString(Person.SURNAME_COLUMN_NAME, TEST_SURNAME), withRowString(Person.NAME_COLUMN_NAME, TEST_NAME)))
                    .check(matches(isDisplayed()));
    }
    

    文本已在搜索视图中成功插入,但在最后一步( onData())上,此错误导致此错误:

    android.support.test.espresso.PerformException: Error performing 'load adapter data' on view 'is assignable from class: class android.widget.AdapterView'.
    at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83)
    at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:80)
    at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:56)
    at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
    at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
    at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
    at android.support.test.espresso.DataInteraction.load(DataInteraction.java:151)
    at android.support.test.espresso.DataInteraction.check(DataInteraction.java:141)
    at com.my_project.android.fragment.PersonFragmentTest.searchTestPerson(PersonFragmentTest.java:125)
    at java.lang.reflect.Method.invoke(Native Method)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at android.support.test.internal.statement.UiThreadStatement.evaluate(UiThreadStatement.java:55)
    at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:270)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:27)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
    at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
    at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
    Caused by: java.lang.RuntimeException: No data found matching: (Rows with column: is "Surname"with String is "AnySurname" and Rows with column: is "Name" with String is "AnyName") contained values: <[]>
    at android.support.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:96)
    at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    

    测试已完成。

0 个答案:

没有答案