DefaultFailureHandler $ AssertionFailedWithCauseError:想要匹配1个意图。实际上匹配2个意图

时间:2017-05-30 13:08:28

标签: android-espresso

您好,我正在点击浓咖啡中的点击按钮开始另一个活动。第一次一切正常,当第二次调用相同的方法时,我得到这样的错误,请帮我解决这个问题。

这是我在两个不同地方打电话的方法:

    private void sendMailTest() {

        onView(withId(R.id.bill_view_send_mail)).perform(scrollTo(), click());
//        Intents.init();
//        activityIntentsTestRule.launchActivity(new Intent());
        intended(hasComponent(SearchBillSendMailActivity.class.getName()));
//        Intents.release();
        pauseTestFor(5000);
}

这就是我得到的:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 2 intents.

IntentMatcher: has component: has component with: class name: is "com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String

Matched intents:
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])

Recorded intents:
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.AppointmentDiscountActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{amount=200.0, nameType=1}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2830}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2831}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2832}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2833}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:580)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:92)
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.check(ViewInteraction.java:158)
at android.support.test.espresso.intent.Intents.intended(Intents.java:187)
at android.support.test.espresso.intent.Intents.intended(Intents.java:169)
at com.wenzins.lab.TestPrepareBill.sendMailTest(TestPrepareBill.java:341)
at com.wenzins.lab.TestPrepareBill.validateCardWithoutAddingItems(TestPrepareBill.java:502)
at com.wenzins.lab.TestPrepareBill.verifyInputs(TestPrepareBill.java:303)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
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 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:1867)
Caused by: junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 2 intents.

IntentMatcher: has component: has component with: class name: is "com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String

Matched intents:
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])

Recorded intents:
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.AppointmentDiscountActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{amount=200.0, nameType=1}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2830}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2831}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2832}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.bill.BillViewActivity (has extras) } handling packages:[[com.wenzinslaboratory.lab.foe]], extras:[Bundle[{billingInvoiceId=2833}]])
-Intent { cmp=com.wenzinslaboratory.lab.foe/com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity } handling packages:[[com.wenzinslaboratory.lab.foe]])
at junit.framework.Assert.fail(Assert.java:50)
at android.support.test.espresso.intent.VerificationModes$Times.verify(VerificationModes.java:87)
at android.support.test.espresso.intent.Intents.internalIntended(Intents.java:282)
at android.support.test.espresso.intent.Intents$2.check(Intents.java:190)
at android.support.test.espresso.ViewInteraction$2.run(ViewInteraction.java:170)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

1 个答案:

答案 0 :(得分:0)

如果没有看到有问题的Espresso测试,很难给出准确的答案,但是如果您的按钮点击触发com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity的Intent,则此行为完全有意义。

您可以通过以下几种方式之一解决问题:

使用times(int times)VerificationMode作为Intents.intended()调用的一部分或:

在第一次按下按钮后验证你的Intent被触发后,调用Intents.release()。

无论哪种方式,发布您的测试和您想要的最终状态以获得更好的答案。