Skip to content

Instantly share code, notes, and snippets.

@jabubuck
Created February 25, 2019 00:36
Show Gist options
  • Save jabubuck/c24000536a0ce8b6eb39dfa7972a9616 to your computer and use it in GitHub Desktop.
Save jabubuck/c24000536a0ce8b6eb39dfa7972a9616 to your computer and use it in GitHub Desktop.
Self reference for writing unitt tests with mockito
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import org.junit.Test
class Tests {
@Test
fun testname_callsfunctionname() {
//Instantiate Presenter
val presenter = MyPresenter()
//Stub the view and attach it
val view: MyPresenter.View = mock()
presenter.attachView(view)
//Test the function
presenter.functionToTest(PARAMETER)
//Verify view has done something
verify(view).functionName()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment