spek

 spek

spek

3c4e24fd827c789cb67a9f759f057b06?s=128

Shinnosuke Kugimiya

November 21, 2017
Tweet

Transcript

  1. 0JTJY4XJGU,PUMJO߹ಉษڧձ

  2. ࣗݾ঺հ w LHNZTIJO ఝٶ Ͱ͢ w "OESPJEΤϯδχΞͰ͢ w "OESPJEΤϯδχΞͰ͢ w

    0JTJYͰٕज़ΞυόΠβʔతͳ͜ͱ ͯ͠·͢
  3. 4QFLͱ͸

  4. ίʔυྫ͔Β

  5. ·ͣ͸௨ৗͷςετΛ ݟͯΈΔ

  6. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) }
  7. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } ςετͱͯ͠͸໰୊ͳ͍͕ɺ Կ͕ࣄલ৚݅Ͱ ԿΛͨ࣌͠ʹ ԿΛอূ͢Δςετͳͷ͔ ͺͬͱݟΘ͔Βͳ͍
  8. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } ࣄલ৚݅
  9. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } QSFTFOUFSͷPO$SFBUF7JFX͕ݺ͹Εͨ࣌ʹ
  10. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ
  11. @Test fun onCreateView() { val workId = WorkId(RandomHelper.randomString()) val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) val presenter = WorkDetailPresenter( getWorkUseCase, getEpisodeListUseCase, Schedulers.trampoline(), errorHandler ) presenter.setUp( view, screenTransition, workId.value ) presenter.onCreateView() val expectedViewModel = WorkDetailViewModelConverter.convertToViewModel( work, episodes ) Mockito.verify(view).setUp(expectedViewModel) } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ ͜ͷΑ͏ʹॱংΛపఈ͢Δ͜ͱ ͦ͏͍͏ॱংͰ͋Δ͜ͱΛ஌͍ͬͯΔ͜ͱͰ Θ͔Γ΍͘͢ͳΔ͕ Ͱ͖Δ͜ͱͳΒڧ੍తͩͬͨΓΫϥεͷߏ଄Ͱ දݱ͍ͨ͠
  12. 4QFLͰॻ͍ͨ ςετΛΈΔ

  13. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } }
  14. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } Կ͕ࣄલ৚݅Ͱ ԿΛͨ࣌͠ʹ ԿΛอূ͢Δςετͳͷ͔ ͺͬͱݟͰΘ͔Δ
  15. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } ࣄલ৚݅
  16. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } QSFTFOUFSͷPO$SFBUF7JFX͕ݺ͹Εͨ࣌ʹ
  17. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ
  18. given("WorkUseCase return work and EpisodeListUseCase return episodes") { val work

    = DomainHelper.work() val episodes = listOf( DomainHelper.episode(), DomainHelper.episode(), DomainHelper.episode() ) Mockito.`when`(workUseCase.execute(workId)).thenReturn(Maybe.just(work)) Mockito.`when`(episodeListUseCase.execute(workId)).thenReturn(Single.just(episodes)) on("onCreateView") { presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkDetailViewModelConverter.convertToViewModel( work, episodeList ) Mockito.verify(view).setUp(expected) } } } WJFXTFU6Q 7JFX.PEFM ͕ݺ͹ΕΔ͜ͱΛ͔֬ΊΔςετ Θ͔Δ
  19. 4QFLͷࢥ૝

  20. 4QFL w 6OJU5FTU͸ڀۃతʹ͸࢓༷ͩ w ͋Δঢ়گͰ͋Δ͜ͱΛͨ͠Β͋ΔৼΔ෣͍Λ͢Δ w ͭ·Γɺ4QFL͸࢓༷ϑϨʔϜϫʔΫͩ

  21. "OESPJE΁ͷಋೖ

  22. buildscript { repositories { maven { url "http://dl.bintray.com/jetbrains/spek" } }

    } 5PQMFWFMCVJMEHSBEMF
  23. dependencies { : testImplementation "org.jetbrains.spek:spek-api:$kotlin_version" testImplementation "org.jetbrains.spek:spek-junit-platform-engine: $kotlin_version" testImplementation "org.jetbrains.spek:spek-subject-extension:

    $kotlin_version" // option testImplementation "org.junit.platform:junit-platform-runner:1.0.0" } .PEVMFMFWFMCVJMEHSBEMF
  24. ࢖͍ํ

  25. @RunWith(JUnitPlatform::class) class BeforeSeasonWorkListPresenterTest : Spek({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.jav given("GetBeforeSeasonWorkListUseCase

    return workList") { val works = DomainHelper. works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } })
  26. @RunWith(JUnitPlatform::class) class BeforeSeasonWorkListPresenterTest : Spek({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.jav given("GetBeforeSeasonWorkListUseCase

    return workList") { val works = DomainHelper. works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() val presenter = BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) presenter.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } }) HJWFO PO JUΛ࢖ͬͯςετΛॻ͚ͩ͘
  27. 4VCKFDU4QFL

  28. @RunWith(JUnitPlatform::class) internal class BeforeSeasonWorkListPresenterSpec : SubjectSpek<BeforeSeasonWorkListPresenter>({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.java)

    subject { BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) } given("GetBeforeSeasonWorkListUseCase return workList") { val works = DomainHelper.works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() subject.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } })
  29. @RunWith(JUnitPlatform::class) internal class BeforeSeasonWorkListPresenterSpec : SubjectSpek<BeforeSeasonWorkListPresenter>({ val getBeforeSeasonWorkListUseCase = Mockito.mock(GetBeforeSeasonWorkListUseCase::class.java)

    subject { BeforeSeasonWorkListPresenter(getBeforeSeasonWorkListUseCase) } given("GetBeforeSeasonWorkListUseCase return workList") { val works = DomainHelper.works() Mockito.`when`(getBeforeSeasonWorkListUseCase.execute()).thenReturn(Single.just(works)) on("onCreateView") { subject.onCreateView() it("should setUp ViewModel to view") { val expected = WorkViewModelConverter.convertToViewModel(works) Mockito.verify(view).setUp(expected) } } } given("") { on("onClickWork") { val viewModel = WorkViewModelFactory.create() subject.onClickWork(viewModel) it("should move to Detail") { Mockito.verify(screenTransition).moveToDetail() } } } }) ςετର৅Ϋϥε͕Θ͔Γ΍͍͢
  30. ଞʹ΋ w HJWFOPOJU͚ͩͰͳ͘EFTDSJCFJUͷܗͰ΋ॻ͚ Δ w CFGPSF(SPVQ BGUFS&BDI5FTUͳͲϑοΫͰ͖Δ w NFNPJ[FEͰॻ͘ςετͷͨͼʹ࡞Γ௚ͨ͠ΓͰ ͖Δ

    w YQSFpYΛ͚ͭΕ͹QFOEJOHʹͰ͖Δ YHJWFO YJUͳ Ͳ
  31. Ҿ͔͔ͬͬͨΓͨ͠ͱ ͜Ζ

  32. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶃ w !3VO8JUI +6OJU1MBUGPSNDMBTT Λ͚ͭͳ͍ͱೝ ࣝ͞Εͳ͍ w UFTUΛ૸Βͤͨͱ͖ʹɺGBJM͞ΕΔ͸ͣͷςετ ͕GBJM͠ͳ͍ͷͰؾ͔ͮͳ͍Մೳੑ͕͋Δ ˞+6OJUͳΒ͚ͭͳͯ͘΋͍͍

    Έ͍ͨ
  33. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶄ ύοέʔδ৘ใ͕ফ͑Δʜ

  34. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶄ Ͳͷςετ͔Θ͔ΓͮΒ͍

  35. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶅ Spek { val a: A = Mockito.mock(A::class.java) given() {

    Mockito.when(a.execute).thenReturn("a") on() { it() { assertEquals("a", a.execute) } } } } ͜ͷςετ͸1BTT 'BJM
  36. Ҿ͔͔ͬͬͨΓͨ͠ͱ͜Ζᶅ Spek { val a: A = Mockito.mock(A::class.java) given() {

    Mockito.when(a.execute).thenReturn("a") on() { it() { assertEquals("a", a.execute) } } } } 1BTT
  37. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } ͜ͷςετ͸1BTT 'BJM
  38. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } }
  39. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } 1BTT 'BJM
  40. Spek { val a: A = Mockito.mock(A::class.java) given() { Mockito.when(a.execute).thenReturn("a")

    on() { it() { assertEquals("a", a.execute) } } } given() { Mockito.when(a.execute).thenReturn("b") on() { it() { assertEquals("b", a.execute) } } } } ΋ͬͱ΋Լʹ͋Δ΋ͷউͪ
  41. Spek { val a: A = Mockito.mock(A::class.java) given() { beforeGroup

    { Mockito.when(a.execute).thenReturn(“a”) } on() { it() { assertEquals("a", a.execute) } } } given() { beforeGroup { Mockito.when(a.execute).thenReturn(“b”) } on() { it() { assertEquals("b", a.execute) } } } ͜͏͠·͠ΐ͏
  42. ·ͱΊ

  43. ·ͱΊ w Ϣχοτςετͱ͸͢ͳΘͪ࢓༷ͩʂ w 4QFL͸࢓༷ϑϨʔϜϫʔΫͩʂ w HJWFOPOJUͰςετΛॻ͜͏ w 4VCKFDU4QFLͰςετର৅Λ໌֬ʹ w

    ΋ͪΖΜσϝϦοτ΋͋Δ
  44. ࣮ࡍʹ࢖ͬͯΔ༷Λ ݟ͍ͨํ͸ͪ͜Β͔Β w IUUQTHJUIVCDPNLHNZTIJOBOOJDUBOESPJE