2016-12-29 26 views
0

一個功能比方說,我有這個功能(寫在科特林):單元測試驗證傳遞給被稱爲

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

是否可以驗證(單元測試)showChatAssignerFunction被調用時,受讓人爲空或空?謝謝你們!

回答

4

當然,您可以:

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

啊ok了!謝謝你的回答! – elsennov