Upgrade to Pro — share decks privately, control downloads, hide ads and more …

mockito-kotlin

 mockito-kotlin

Android Test Night #2

85cab5fdf09afe3ee78ce3667681915a?s=128

Keisuke Kobayashi

December 15, 2017
Tweet

Transcript

  1. mockito-kotlin Keisuke Kobayashi Android Test Night #2

  2. About Me • Keisuke Kobayashi • GitHub, QIita: kobakei •

    Twitter: kobakei122 • Kyash, Inc • ݸਓࣄۀओ
  3. mockito-kotlin͸͍͍ͧ

  4. mockito-kotlin • KotlinͰMockitoΛ࢖͏ͨΊͷϥΠϒϥϦ • https://github.com/nhaarman/mockito-kotlin • ˒800 over

  5. Ͳ͕͍͍͔͜ • ϞοΫ͕ݟ΍͘͢ͳΔ • Null҆શରԠ • άϩʔόϧؔ਺ͷ௥Ճ • when໰୊ରԠ

  6. Mockito in Java // Java import static org.mockito.Mockito.*; Hoge mock

    = mock(Hoge.class); when(mock.sayHello()).thenReturn("Hello"); when(mock.sayBye()).thenReturn("Bye");
  7. Convert to Kotlin // Kotlin import org.mockito.Mockito.* val mock =

    mock(Hoge::class.java) `when`(mock.sayHello()).thenReturn("Hello") `when`(mock.sayBye()).thenReturn("Bye")
  8. mockito-kotlin // Kotlin import com.nhaarman.mockito_kotlin.* val mock = mock<Hoge> {

    on { sayHello() } doReturn "Hello" on { sayBye() } doReturn "Bye" }
  9. ݟ΍͍͢

  10. Null҆શରԠ • Null҆શͷ͍ͤͰɺMockitoͷanyͰNPE • NonNullͳҾ਺ʹanyΛ౉͢ͱൃੜ • anyͱanyOrNull

  11. άϩʔόϧؔ਺ • any, anyOrNull • atLeast, only, never • verify

    • whenever
  12. when໰୊ • Mockitoͷwhenϝιου • Kotlinͷwhen͸༧໿ޠ • `when`ͱॻ͔͘͠ແ͍ • mockito-kotlinͰ͸୅ΘΓʹwhenever΍on͕ ࢖͑Δ

  13. mockito-kotlin͸͍͍ͧ

  14. Thanks!