2017-05-30 61 views
0

嗨,我開始從另一個點擊按鈕在咖啡的活動。一切工作正常,第一次當同樣的方法被稱爲第二次我得到這樣的錯誤,請幫我解決這個問題。

這是方法我在兩個不同的地方打電話:

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) 

回答

0

這是很難給你一個準確的答案,而不會看到咖啡測試有問題,但如果點擊按鈕觸發了com.wenzinslaboratory.lab.popup.SearchBillSendMailActivity的Intent,則這種行爲總是有意義的。

可以解決的幾種方法之一的問題:時間(INT倍)VerificationMode爲您Intents.intended()調用的一部分或

用途:

調用Intents.release()後驗證您的意圖是在點擊第一次按鈕後觸發的。

無論哪種方式,張貼您的測試和您想要的最終狀態,以獲得更好的答案。

+0

是的我已經嘗試了兩種說法,但仍然有同樣的錯誤。 –

+0

請參閱最新的問題 –

+0

完整的測試未發佈。發佈的方法不是一個完整的測試。你使用什麼測試規則?有沒有@之前/ @之後?作爲此測試的一部分,還發生了什麼?按鈕的onclick在做什麼? – jdonmoyer