如何在Kotlin中的每个函数之后执行定义的函数

时间:2019-07-01 07:34:19

标签: kotlin android-espresso spoon

我正在编写Espresso单元测试代码。 我要做的是在不指定任何操作的情况下截取屏幕截图

takeSpoonScreenshot("")

这是我的AndroidJUnit4测试代码:

@Test
fun givenVideoDetail_whenChooseCurrentItem_thenShowCountLabel() {
    pickerPage {
        clickFirstVideoItem()
    }
    videoDetailPage {
        clickSelectCheckBox()
        assertCountLabel()
    }
}

这是我的VideoDetailPage.kt:

fun videoDetailPage(func: VideoDetailPage.() -> Unit) = VideoDetailPage.apply {
    assertFirstPage()
    func()
}

fun screenshotAfterAction(func: VideoDetailPage.() -> Unit) = VideoDetailPage.apply {
    func()
    takeSpoonScreenshot("")
}

object VideoDetailPage : BaseActions() {
    // Write 'How to test' here

    fun assertFirstPage() {
        resourceIsDisplayed(R.id.send_balloon_image)
        resourceIsDisplayed(R.id.media_detail_item_check_box)
        resourceIsDisplayed(R.id.video_editor_mute_btn)
    }

    fun clickFilterButton() = takeScreenshotAfterFunction {
        clickButton(R.id.image_editor_filter)
    }

    fun clickSelectCheckBox() {
        clickButton(R.id.media_detail_item_check_box)
    }

    fun assertFilterSelectionListIsOpen() {
        resourceIsDisplayed(R.id.media_filter_list)
    }

    fun assertCountLabel() {
        resourceIsDisplayed(R.id.media_editor_selected_count)
    }
}

看到我做了takeScreenshotAfterFunction,但这不合适,因为我应该写takeScreenshotAfterFunction N次。

0 个答案:

没有答案