Skip to content

Instantly share code, notes, and snippets.

@phellipealexandre
Last active November 14, 2020 11:26
Show Gist options
  • Save phellipealexandre/9e75b857d30d7b27339ca1168b665857 to your computer and use it in GitHub Desktop.
Save phellipealexandre/9e75b857d30d7b27339ca1168b665857 to your computer and use it in GitHub Desktop.
Exemplo onde substituímos a dependência de uma API por um Stub e configuramos o retorno desse Stub para ser uma resposta fixa.
@Test
fun `Retrieve notes count from server when requested`() {
val notesApiStub = //Dublê de teste Stub
val noteRepository = NoteRepository(notesApiStub)
//Configuração do Stub. Valor hard-coded retornado será uma lista com 2 notas.
//Esse método será chamado pelo noteRepository.getNoteCount()
val note = //Dublê de teste Dummy
every { notesApiStub.fetchAllNotes() } returns listOf(note, note)
val allNotesCount = noteRepository.getNoteCount()
assertEquals(expected = 2, actual = allNotesCount)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment