android-如何等到烤面包完成?仅在烤面包被先前测试掩盖后才开始第二次测试

android-如何等到烤面包完成?仅在烤面包被先前测试掩盖后才开始第二次测试,第1张

概述这是我的意式浓缩咖啡的测试:@RunWith(AndroidJUnit4::class)classAddTraderActivityNetworkTest{privatevalcontext=InstrumentationRegistry.getInstrumentation().getContext()privatelateinitvarmockServer:MockWebServer@Rule@JvmField

这是我的意式浓缩咖啡的测试:

@RunWith(AndroIDJUnit4::class)class AddTraderActivityNetworkTest {    private val context = InstrumentationRegistry.getInstrumentation().getContext()    private lateinit var mockServer: MockWebServer    @Rule    @JvmFIEld    var addTraderIntentTestRule: IntentsTestRule<AddTraderActivity> = IntentsTestRule(AddTraderActivity::class.java)    @Before    fun setup() {        mockServer = MockWebServer()        mockServer.start(8081)    }    @Test    fun buttonStart_click_clIEntError_showToast() {        mockServer.enqueue(MockResponse()                .setResponseCode(400))        onVIEw(withID(R.ID.baseTextinputEditText))                .perform(typeText(BASE_TEST))        onVIEw(withID(R.ID.quoteTextinputEditText))                .perform(typeText(QUOTE_TEST))        onVIEw(withID(R.ID.startbutton))                .perform(click())        onVIEw(withText(R.string.clIEnt_error)).inRoot(ToastMatcher())                .check(matches(isdisplayed()))    }    @Test    fun buttonStart_click_clIEntError_TraderNotFound_showToast() {        mockServer.enqueue(MockResponse()                .setResponseCode(404)                .setbody(fileUtil.getStringFromfile(context, "Trader_404_not_add.Json")))        onVIEw(withID(R.ID.baseTextinputEditText))                .perform(typeText(BASE_TEST))        onVIEw(withID(R.ID.quoteTextinputEditText))                .perform(typeText(QUOTE_TEST))        onVIEw(withID(R.ID.startbutton))                .perform(click())        onVIEw(withText(R.string.Trader_not_added)).inRoot(ToastMatcher())                .check(matches(isdisplayed()))    }

当统计所有这些测试时,其中之一肯定会失败并显示以下消息:

androIDx.test.espresso.NoMatchingVIEwException: No vIEws in hIErarchy found matching: with string from resource ID: <2131623975>[clIEnt_error] value: ClIEnt ErrorVIEw HIErarchy:+>linearLayout{ID=-1, visibility=VISIBLE, wIDth=566, height=149, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,192)(wrapxwrap) gr=#51 ty=2005 fl=#1000098 fmt=-3 wanim=0x1030004}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}|+->AppCompatTextVIEw{ID=16908299, res-name=message, visibility=VISIBLE, wIDth=416, height=83, has-focus=false, has-focusable=false, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androID.Widget.linearLayout$LayoutParams@b08322e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=75.0, y=33.0, text=Trader not added, input-type=0, ime-target=false, has-links=false}|at dalvik.system.VMStack.getThreadStackTrace(Native Method)at java.lang.Thread.getStackTrace(Thread.java:580)at androIDx.test.espresso.base.DefaultFailureHandler.getUserFrIEndlyError(DefaultFailureHandler.java:96)at androIDx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:59)at androIDx.test.espresso.VIEwInteraction.waitForAndHandleInteractionResults(VIEwInteraction.java:316)at androIDx.test.espresso.VIEwInteraction.check(VIEwInteraction.java:300)at com.myproject.activity.AddTraderActivityNetworkTest.buttonStart_click_clIEntError_showToast(AddTraderActivityNetworkTest.kt:64)at java.lang.reflect.Method.invoke(Native Method)at org.junit.runners.model.FrameworkMethod.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 androIDx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)at androIDx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)at androIDx.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:531)at org.junit.rules.RunRules.evaluate(RunRules.java:20)

发生这种情况是因为开始了新的测试,但是仍然没有隐藏上一测试的吐司.结果我得到了找不到消息的吐司的错误:

androIDx.test.espresso.NoMatchingVIEwException: No vIEws in hIErarchy found matching: with string from resource ID: <2131623975>[clIEnt_error] value: ClIEnt Error

问题是:
我如何才能等到烤面​​包被藏起来并且只有在开始第二次测试之后?

解决方法:

这是Java中的一个函数,用于显示x毫秒的Toast

private Toast myToast;private voID showToast(int ms) {    myToast = Toast.makeText(this, "Your message", Toast.LENGTH_LONG);    new Handler().postDelayed(new Runnable() {        @OverrIDe        public voID run() {            myToast.cancel(); // do this to be sure Toast is gone            // here you can start your new test or set a flag to say Toast is finish        }    }, ms);}
总结

以上是内存溢出为你收集整理的android-如何等到烤面包完成?仅在烤面包被先前测试掩盖后才开始第二次测试全部内容,希望文章能够帮你解决android-如何等到烤面包完成?仅在烤面包被先前测试掩盖后才开始第二次测试所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095225.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存