This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Retrieve all notes when requested`() { | |
//Dublê de teste Fake. Implementa a mesma interface do original. | |
val noteApiFake = FakeNoteApi() | |
val noteRepository = NoteRepository(noteApiFake) | |
val note = //Dublê de teste Dummy | |
noteApiFake.uploadNote(note) | |
noteApiFake.uploadNote(note) | |
//Fake será utilizado por debaixo dos panos com uma implementação real |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Track analytics event when creating new note`() { | |
val analyticsWrapperMock = //Dublê de teste Mock | |
val noteAnalytics = NoteAnalytics(analyticsWrapperMock) | |
noteAnalytics.trackNewNoteEvent(NoteType.Supermarket) | |
//Mock verifica que comportamento específico aconteceu | |
verify(exactly = 1) { analyticsWrapperMock.logEvent("NewNote", "SuperMarket") } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Track analytics event when creating new note`() { | |
val analyticsWrapperSpy = //Dublê de teste Spy | |
val noteAnalytics = NoteAnalytics(analyticsWrapperSpy) | |
//Spy grava o comportamento por debaixo dos panos | |
noteAnalytics.trackCreateNewNoteEvent(NoteType.Supermarket) | |
//Spy verifica que comportamento ocorreu baseado em implementação interna | |
analyticsWrapperSpy.assertThatNewNoteEventWasRegistered("SuperMarket") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Retrieve notes count from server when requested`() { | |
val notesApiStub = mockk<NotesApi>() //Dublê de teste Stub | |
val noteRepository = NoteRepository(notesApiStub) | |
val note = generateDummyNote() //Método privado | |
every { notesApiStub.fetchAllNotes() } returns listOf(note, note) | |
val allNotesCount = noteRepository.getNoteCount() | |
assertEquals(expected = 2, actual = allNotesCount) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Track analytics event when creating new note`() { | |
val analyticsWrapperMock = mockk<AnalyticsWrapper>() //Dublê de teste Mock | |
val noteAnalytics = NoteAnalytics(analyticsWrapperMock) | |
noteAnalytics.trackNewNoteEvent(NoteType.Supermarket) | |
//Mock verifica que comportamento específico aconteceu | |
verify(exactly = 1) { analyticsWrapperMock.logEvent("NewNote", "SuperMarket") } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Update registered note count when registering a new note in empty repository`() { | |
val dummyNote = //Dummy | |
noteRepository.registerNote(dummyNote) //Just filling the parameter, the double's content is not relevant for the test | |
val allNotes = noteRepository.getNotes() | |
assertEquals(expected = 1, actual = allNotes.size) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----- Literal dummy ----- | |
val dummyPrice = 10.0 | |
//----- Generated dummy ----- | |
val dummyCustomer = CustomerTestBuilder.build() | |
//----- Alternative empty implementation ----- | |
val dummyNote = DummyNote() | |
class DummyNote(): Note //No implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Retrieve notes count from server when requested`() { | |
val notesApiStub = //Stub | |
val note = //Dummy | |
val noteRepository = NoteRepository(notesApiStub) //System under test | |
//Stub configuration. Hard-coded value returned will be a list with 2 entries. | |
//This method is going to be called by noteRepository.getNoteCount() | |
every { notesApiStub.fetchAllNotes() } returns listOf(note, note) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `Retrieve all notes when requested`() { | |
val noteApiFake = FakeNoteApi() //Fake double implementing the same interface as the original | |
val noteRepository = NoteRepository(noteApiFake) //System under test | |
val note = //Dummy | |
noteApiFake.uploadNote(note) //Configuring the fake | |
noteApiFake.uploadNote(note) //Configuring the fake | |
//Fake with real and lightweight implementation is going to be used under the hoods | |
val allNotes = noteRepository.getNotes() |