article banner

Exercise: Unit testing

Implement unit tests for the SynchronizeUserUseCase class in SynchronizeUserUseCaseTest using fake objects.

class CorrectCardsUseCase( private val view: AnkiView, private val cardsRepository: AnkiCardsRepository, ) { suspend fun start() { val progressBar = AnkiProgressBar(size = Small) view.show(progressBar) try { cardsRepository.correctCards() } finally { view.hide(progressBar) } val dialog = AnkiDialog( title = "Success", text = "Cards correction successful", okButton = AnkiDialog.Button("OK"), ) view.show(dialog) } }

Use CorrectCardsUseCaseTest and SynchronizeCardsUseCaseTest as inspiration. You can find those classes in the repository MarcinMoskala/kotlin-exercises in the package effective.anki.