【问题标题】:Unit Test Verify a Function Passed to be Called单元测试验证传递给调用的函数
【发布时间】:2016-12-29 04:27:42
【问题描述】:

假设我有这个功能(用 Kotlin 编写):

fun determineBottomBarView(assignee: String?,
                           showChatAssignerFunction: () -> Unit,
                           showChatComposerFunction: () -> Unit,
                           hideChatComposerAndAssignerFunction: () -> Unit) {
    if (assignee.isNullOrEmpty()) {
        showChatAssignerFunction()
    } else {
        if (assignee.equals(localRequestManager.getUsername())) {
            showChatComposerFunction()
        } else {
            hideChatComposerAndAssignerFunction()
        }
    }
}

是否可以验证(在单元测试中)showChatAssignerFunction 在受理人为空或为空时被调用?谢谢大家!

【问题讨论】:

    标签: android function unit-testing kotlin verify


    【解决方案1】:

    当然可以:

    @Test
    fun `just testing`() {
        var showedChatAssigner = false
        var showChatComposer = false
        var didHideChat = false
    
        determineBottomBarView(null,{ showedChatAssigner = true }, { showChatComposer = true }, { didHideChat = true })
    
        assertThat(showedChatAssigner, equalTo(true))
        assertThat(showChatComposer, equalTo(false))
        assertThat(didHideChat, equalTo(false))
    }
    

    【讨论】:

    • 啊,好吧!谢谢你的回答!
    猜你喜欢
    • 2014-10-21
    • 2017-01-29
    • 2013-04-11
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多