Dividing Model into layers and implementing Unit Test

Dividing Model into layers and implementing Unit Test

8bd326566d5bfb6e2d8371a0b85d6a15?s=128

kamui_project

February 26, 2019
Tweet

Transcript

  1. ModelΛ LayerͰ෼͚ͯ Unit Testͷ؍఺Λ໌֬͢Δ potatotips #59

  2. About me • Name: ͔Ή͍ (Twitter: @kamui_project) • Company: DMM.com

    • App: MENUS • Community: ϖϯΪϯଜ
  3. None
  4. None
  5. I will tell you …

  6. Unit Tests for iOS

  7. None
  8. None
  9. We implemented unit testing like this …

  10. HogeTests Hoge

  11. Architecture • GUI Architecture -> MVVM • System Architecture ->

    Layered Architecture
  12. Testability! RxSwift! DDD! CI/CD! Availability! Readability! Maintainability! Scalability! XcodeGen! All

    Swift!
  13. EoT(Ease of Testing)! RxSwift! DDD! CI/CD! Availability! Readability! Maintainability! Scalability!

    XcodeGen! All Swift!
  14. Layered Architecture IUUQTMJUUMFIBOETIBUFOBCMPHDPNFOUSZEEEBSDIJUFDUVSF Ҿ༻৽ଔʹ΋఻ΘΔυϝΠϯۦಈઃܭͷΞʔΩςΫνϟઆ໌<%%%>

  15. Layer • Presentation: ViewModel • Domain: Service • UseCase: UseCase

    • Infrastructure: Repository
  16. Layer • Presentation: ViewModel • Domain: Service • UseCase: UseCase

    • Infrastructure: Repository Tests Tests Tests Tests
  17. Code Example - User Information -

  18. UserViewModel ը໘ϩʔυ࣌ʹ6TFS৘ใΛऔಘ͠ը໘ʹ6TSF৘ใΛ౉͢ GVODVTFS8JUI7JFX8JMM"QQFBS \ JOQVUT WJFX8JMM"QQFBSBT0CTFSWBCMF TVCTDSJCF PO/FYU\<XFBLTFMG> JO TFMG

    EFQFOEFODJFTHFU6TFS6TF$BTFFYFDVUF NBQ $POWFSUFSTIBSFEDPOWFSU5P6TFS #JOEJOH%BUB TVCTDSJCF PO4VDDFTT\<XFBLTFMG> VTFS#JOEJOH%BUB JO TFMG VTFS3FMBZBDDFQU VTFS#JOEJOH%BUB  ^  EJTQPTFE CZTFMG EJTQPTF#BH  ^  EJTQPTFE CZEJTQPTF#BH  ^
  19. දࣔʹ͓͚Δؔ৺ࣄ Presentation:

  20. UserViewModelTests GVODUFTUը໘ϩʔυ࣌ʹ6TFS৘ใΛऔಘ͠ը໘ʹ6TSF৘ใΛ౉͢͜ͱ \ MFUVTFS6TFS)FMQFSTIBSFEVTFS  $VDLPPͰελϒੜ੒ TUVC NPDL(FU6TFS6TF$BTF \ QSPYZ

    JO XIFO QSPYZFYFDVUF UIFO3FUVSO KVTU VTFS  ^ EP\ MFUVTFS#JOEJOH%BUBTVCKFDUPVUQVUVTFS#JOEJOH%BUBBT0CTFSWBCMF TIBSF SFQMBZ  TDPQFXIJMF$POOFDUFE  VTFS#JOEJOH%BUBTVCTDSJCF EJTQPTFE CZEJTQPTF#BH  ը໘දࣔ WJFX8JMM"QQFBS3FMBZBDDFQU USVF  MFUFWFOUUSZVTFS#JOEJOH%BUBUBLF  UP#MPDLJOH UP"SSBZ  9$5"TTFSU&RVBM FWFOUDPVOU   ^DBUDI\ 9$5'BUJM  ^ ^
  21. UserUseCase 6TFS৘ใऔಘॲཧΛ࣮ߦ GVODFYFDVUF 4JOHMF6TFS\ SFUVSOVTFS3FQPTJUPSZpOE  ^

  22. Presentation૚ͷͨΊͷDomainૢ࡞ʹ͓͚Δؔ৺ࣄ UseCase: ※(Evansຊ)Ͱ͸Application૚ͱ঺հ͞Ε͍ͯ·͕͢ɺDomainObjectͷ஋Λૢ࡞͠ͳ͍ɾӬଓԽ΁ͷӨڹ ͷ͋Δૢ࡞Λ͠ͳ͍ͱ͍͏఺Ͱ໨త͸ࣅ͍ͯ·͢

  23. UserUseCaseTests GVODUFTU6TFS৘ใऔಘॲཧΛ࣮ߦ͢Δ͜ͱ \ MFUVTFS6TFS)FMQFSTIBSFEVTFS  $VDLPPͰελϒੜ੒ TUVC NPDL6TFS3FQPTJUPSZ \ QSPYZ

    JO XIFO QSPYZpOE UIFO3FUVSO KVTU VTFS  ^ MFUFYFDVUFTVCKFDUFYFDVUF BT0CTFSWBCMF TIBSF SFQMBZ TDPQFXIJMF$POOFDUFE  FYFDVUFTVCTDSJCF EJTQPTFE CZEJTQPTF#BH  EP\ MFUVTFSUSZFYFDVUFUBLF  UP#MPDLJOH MBTU  9$5"TTFSU/PU/JM VTFS  9$5"TTFSU&RVBM VTFSJE   9$5"TTFSU&RVBM VTFSOBNF l͔Ή͍z  9$5"TTFSU&RVBM VTFSBHF   ^DBUDI\ 9$5'BJM  ^ ^
  24. UserRepository 6TFS৘ใΛ6TFS"QJʹ໰͍߹Θͤͯऔಘ͢Δ GVODpOE 4JOHMF6TFS\ SFUVSO6TFS"QJ(FU6TFS SYTFOE NBQ \SFTQPOTF6TFSJO SFUVSO6TFS 

    JE6TFS*E JESFTQPOTFJE  OBNFSFQPOTFOBNF  BHFSFTQPOTFBHF  ^  ^
  25. ӬଓԽʹ͓͚Δؔ৺ࣄ Infrastructure:

  26. UserRepositoryTests PWFSSJEFGVODTFU6Q \ .PDLJOHKBZͰελϒੜ੒ TUVC IUUQ HFU VSJ4USJOHlVTFSTl KTPO <lJEz

    dׂѪd>  ^ GVODUFTU6TFS৘ใΛ6TFS"QJʹ໰͍߹Θͤͯऔಘ͢Δ͜ͱ \ MFUVTFS6TFS)FMQFSTIBSFEVTFS  MFUpOETVCKFDUpOE BT0CTFSWBCMF TIBSF SFQMBZ TDPQFXIJMF$POOFDUFE  pOETVCTDSJCF EJTQPTFE CZEJTQPTF#BH  MFUFYQFYQFDUBUJPO EFTDSJQUJPOlz  EP\ MFUVTFSUSZpOEUBLF  UP#MPDLJOH TJOHMF  9$5"TTFSU/PU/JM VTFS  9$5"TTFSU&RVBM VTFSJE   ddׂѪdd ^DBUDI\ 9$5'BUJM  ^ ^
  27. Conclusion • Before: Point of view? • After: ɹArchitcture-pattern ->

    Modeling -> Carify Responsibility ->
  28. In the end • We’re Hiring!!! -> Especially, Developer! •

    Firstly… Let’s have lunch together!
  29. Thank you!