单元测试验证通过被调用的功能

比方说,我有这个功能(写在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是否被调用? 谢谢你们!

你当然可以:

 @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)) }