简体   繁体   English

Kotlin lambdas 使用 jaredsburrows 的 Spoon 插件停止代码的问题

[英]Issue with Kotlin lambdas halting code using Spoon plug-in by jaredsburrows

I'm attempting to run an espresso test on a simple pre-fabricated Android app using the Spoon plugin to take screenshots and test on multiple devices in Kotlin.我正在尝试使用 Spoon 插件在一个简单的预制 Android 应用程序上运行 espresso 测试,以截取屏幕截图并在 Kotlin 中的多个设备上进行测试。 I looked at the official Github example but can't seem to get it working.我查看了官方 Github 示例,但似乎无法正常工作。 I'm thinking it might be an issue with my understanding of lambda functions in Kotlin, as I've never used them before.我认为这可能是我对 Kotlin 中 lambda 函数的理解的问题,因为我以前从未使用过它们。

Currently, my code is freezing after the first command in the lambda function.目前,我的代码在 lambda 函数中的第一个命令之后冻结。

 @Test fun firstFragmentTest() { scenario.scenario.onActivity { activity -> Log.d("First Fragment Test: ", "Testing to make sure first fragment is accurate") //checking to see if center text is accurate onView(withId(R.id.textview_first)).check(matches(withText("Hello first fragment"))) Log.d("First Fragment Test: ", "Center text is accurate") Spoon.screenshot(activity, "FirstFragment", "ButtonTests", "firstFragmentTest") //checking to see if button text is accurate onView(withId(R.id.button_first)).check(matches(withText("Next"))) Log.d("First Fragment Test: ", "Button text is accurate") //checking to see if top text is accurate //onView(withId(R.id.FirstFragment)).check(matches(withText("First Fragment"))) Log.d("First Fragment Test: ", "First fragment text is accurate") } }

This is my logcat:这是我的日志:

 2022-05-31 13:43:39.640 2155-2190/com.example.problem2_21 D/Previous Button Test:: Testing functionality of previous button 2022-05-31 13:43:39.643 2155-2155/com.example.problem2_21 I/ViewInteraction: Performing 'single click' action on view view.getId() is <2131230815/com.example.problem2_21:id/button_second> 2022-05-31 13:43:39.972 2155-2190/com.example.problem2_21 D/Previous Button Test:: Previous button pressed 2022-05-31 13:43:39.973 2155-2190/com.example.problem2_21 D/Previous Button Test:: First fragment screen should be displayed 2022-05-31 13:43:39.974 2155-2155/com.example.problem2_21 D/First Fragment Test:: Testing to make sure first fragment is accurate

As you can see, the test stops running after the first line of the lambda.如您所见,测试在 lambda 的第一行之后停止运行。 I have multiple test functions that lead into this one, which aren't set-up for Spoon yet and don't use lambda functions, that work fine.我有多个测试函数可以导入这个函数,这些函数还没有为 Spoon 设置,也没有使用 lambda 函数,可以正常工作。

I actually figured it out, in case anyone else has the same issue.我实际上想通了,以防其他人有同样的问题。 I just had to place the lambda with the screenshot after the test code like this:我只需要在测试代码之后放置带有屏幕截图的 lambda,如下所示:

 @Test fun firstFragmentTest() { Log.d("First Fragment Test: ", "Testing to make sure first fragment is accurate") //checking to see if center text is accurate onView(withId(R.id.textview_first)).check(matches(withText("Hello first fragment"))) Log.d("First Fragment Test: ", "Center text is accurate") //checking to see if button text is accurate onView(withId(R.id.button_first)).check(matches(withText("Next"))) Log.d("First Fragment Test: ", "Button text is accurate") //checking to see if top text is accurate //onView(withId(R.id.FirstFragment)).check(matches(withText("First Fragment"))) Log.d("First Fragment Test: ", "First fragment text is accurate") scenario.scenario.onActivity { activity -> Spoon.screenshot(activity, "FirstFragment", "ButtonTests", "firstFragmentTest") } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM