想要匹配1个意图。实际匹配的0个意图

时间:2019-06-05 14:37:07

标签: android-espresso android-uiautomator

我有活动TradersActvity和菜单。单击此菜单后,开始活动AddTraderActivity。 当单击后退按钮时,它将返回到上一个活动= TradersActivity。 真好 现在,我想使用Espresso和UI Automator对此进行测试。

这里测试:

@RunWith(AndroidJUnit4::class)
class TradersActivityTest {

   @Rule
    @JvmField
    var tradersIntentTestRule = IntentsTestRule(TradersActivity::class.java, false, false)


    @Before
    fun beforeEach() {
       tradersIntentTestRule.launchActivity(Intent())
   }


 @Test
    fun myTest() {
        onView(withId(add_trader))
                .perform(click())
        Espresso.closeSoftKeyboard()
        uiDevice.pressBack()
        intended(hasComponent(TradersActivity::class.java.name))
}

}

但是myTest失败,并显示以下消息:

D/LifecycleMonitor(24815): running callback: androidx.test.rule.ActivityTestRule$LifecycleCallback@70d298
D/LifecycleMonitor(24815): callback completes: androidx.test.rule.ActivityTestRule$LifecycleCallback@70d298
E/TestRunner(24815): failed: myTestcom.myproject(com.myproject.activity.TradersActivityTest)
E/TestRunner(24815): ----- begin exception -----
E/TestRunner(24815): androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: Wanted to match 1 intents. Actually matched 0 intents.
E/TestRunner(24815): 
E/TestRunner(24815): IntentMatcher: has component: has component with: class name: is "com.myproject.ui.activity.TradersActivity" package name: an instance of java.lang.String short class name: an instance of java.lang.String
E/TestRunner(24815): 
E/TestRunner(24815): Matched intents:[]
E/TestRunner(24815): 
E/TestRunner(24815): Recorded intents:
E/TestRunner(24815): -Intent { cmp=com.myproject.debug/com.myproject.ui.activity.AddTraderActivity } handling packages:[[com.myproject.debug]])
E/TestRunner(24815):    at dalvik.system.VMStack.getThreadStackTrace(Native Method)
E/TestRunner(24815):    at java.lang.Thread.getStackTrace(Thread.java:580)
E/TestRunner(24815):    at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:96)
E/TestRunner(24815):    at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)
E/TestRunner(24815):    at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:318)
E/TestRunner(24815):    at androidx.test.espresso.ViewInteraction.check(ViewInteraction.java:300)
E/TestRunner(24815):    at androidx.test.espresso.intent.Intents.intended(Intents.java:190)
E/TestRunner(24815):    at androidx.test.espresso.intent.Intents.intended(Intents.java:170)
E/TestRunner(24815):    at com.myproject.activity.TradersActivityTest.myTestcom.myproject(TradersActivityTest.kt:394)
E/TestRunner(24815):    at java.lang.reflect.Method.invoke(Native Method)
E/TestRunner(24815):    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
E/TestRunner(24815):    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
E/TestRunner(24815):    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
E/TestRunner(24815):    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
E/TestRunner(24815):    at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
E/TestRunner(24815):    at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
E/TestRunner(24815):    at androidx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)
E/TestRunner(24815):    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
E/TestRunner(24815):    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
E/TestRunner(24815):    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
E/TestRunner(24815):    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
E/TestRunner(24815):    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
E/TestRunner(24815):    at androidx.test.runner.AndroidJUnit4.run(AndroidJUnit4.java:104)
E/TestRunner(24815):    at org.junit.runners.Suite.runChild(Suite.java:128)
E/TestRunner(24815):    at org.junit.runners.Suite.runChild(Suite.java:27)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
E/TestRunner(24815):    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
E/TestRunner(24815):    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
E/TestRunner(24815):    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
E/TestRunner(24815):    at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
E/TestRunner(24815):    at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
E/TestRunner(24815):    at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
E/TestRunner(24815):    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)
E/TestRunner(24815): Caused by: junit.framework.AssertionFailedError: Wanted to match 1 intents. Actually matched 0 intents.
E/TestRunner(24815): 
E/TestRunner(24815): IntentMatcher: has component: has component with: class name: is "com.myproject.ui.activity.TradersActivity" package name: an instance of java.lang.String short cl
E/TestRunner(24815): ----- end exception -----

0 个答案:

没有答案