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

Laravelで始めるテスト生活

bmf_san
February 16, 2019

 Laravelで始めるテスト生活

bmf_san

February 16, 2019
Tweet

More Decks by bmf_san

Other Decks in Programming

Transcript

  1. LaravelͰ࢝ΊΔςετੜ׆
    @bmf_san
    @Laravel JP Conference 2019
    2019/02/16

    View full-size slide

  2. ࣗݾ঺հ
    Software engineer
    @bmf_san

    View full-size slide

  3. ࠓ೔࿩͢͜ͱ
    • What?
    • LaravelͰػೳςετॻ͘ͷ͸͍͍ͧʂ
    • ؆୯ʹ࢝Ί΍͍͢؀ڥ
    • ෼͔Γ΍͍͢APIʢςετϝιουʣ
    • Who
    • ςετ͔͍ͨ͜ͱͳ͍ਓ
    • ॻ͍ͨࣄ͋Δਓ͸͜Ε͔Βॻ͜͏ͱ͢ΔਓͷͨΊʹɾɾ

    View full-size slide

  4. ػೳςετ is Կʁ
    • γεςϜ͕Ϣʔβʔ͔ΒΈͨ࢓༷௨Γಈ͔֬͘ೝ͢Δ
    • ݁߹ςετͷҰํࣜ
    • ϒϥ΢βͰͷखಈςετʹࣅ͍ͯΔ
    • →ςετॻ͍ͨ͜ͱͳ͍ਓͰ΋औΓ૊Έқ͍͸ͣ

    View full-size slide

  5. ͳͥLaravelͰػೳςετΛ࢝ΊΔͷ͔ʁ
    • ػೳςετAPI͕ॆ࣮
    • Illuminate\Foundation\Testing
    • Github - laravel/browser-kit-testing
    • 5.4͘Β͍͔Βผύοέʔδʹͳͬͯ͠·ͬͨ
    • 5.4ʙͳΒLaravel Dusk࢖ͬͨ΄͏͕Α͍͔΋

    View full-size slide

  6. LaravelͰػೳςετΛ࢝ΊΔ
    • ؀ڥߏஙʢLaravel5.4ʙʣ
    • ςετ༻DBηοτΞοϓ
    • config/database.php
    • phpunit.xml
    • .env
    • composer require laravel/browser-kit-testing —dev
    • 5.4~ͷ৔߹

    View full-size slide

  7. ϦϙδτϦ
    • ࡶʹػೳςετΛମײͰ͖ͦ͏ͳ؀ڥ͓͍ͭͬͯ͘
    ͨ
    • Github - bmf-san/laravel-test-handson

    View full-size slide

  8. ςετΛॻ͍ͯΈΔ
    • Github - bmf-san/laravel-test-handson
    • Ϣʔβʔొ࿥͕Ͱ͖Δ
    • ϩάΠϯ͕Ͱ͖Δ
    • هࣄͷ࡞੒͕Ͱ͖Δ
    • هࣄͷฤू͕Ͱ͖Δ
    • هࣄͷ࡟আ͕Ͱ͖Δ
    • etc …

    View full-size slide

  9. Ϣʔβʔొ࿥ͷػೳςετ
    ਖ਼͘͠ೖྗͯ͠ૹ৴͢ΔͱɺIPNFʹϦμΠϨΫτ
    SFHJTUFS

    View full-size slide

  10. Ϣʔβʔొ࿥ͷػೳςετ
    IPNF

    View full-size slide

  11. Ϣʔβʔొ࿥ͷػೳͷςετ

    View full-size slide

  12. ϩάΠϯͷػೳςετ
    ਖ਼͘͠ೖྗͯ͠ૹ৴͢ΔͱɺIPNFʹϦμΠϨΫτ
    MPHJO

    View full-size slide

  13. ϩάΠϯͷػೳςετ
    IPNF

    View full-size slide

  14. ϩάΠϯͷػೳͷςετ

    View full-size slide

  15. هࣄ࡞੒ͷػೳςετ
    ਖ਼͘͠ೖྗͯ͠ૹ৴͢ΔͱɺQPTUʹϦμΠϨΫτ
    QPTUDSFBUF
    ϩάΠϯ͍ͯ͠ͳ͍ͱΞΫηεͰ͖ͳ͍ϖʔδ

    View full-size slide

  16. هࣄ࡞੒ͷػೳςετ
    QPTU

    View full-size slide

  17. هࣄ࡞੒ͷػೳςετ

    View full-size slide

  18. ͦͷଞͷAPI
    DMJDL ϦϯΫΛΫϦοΫ͠ͱ͖ͷϦΫΤετɾϨεϙϯεΛݕূͰ͖Δ
    TFMFDU
    ϥδΦϘλϯ·ͨ͸υϩοϓμ΢ϯϦετͷ߲໨Λબ୒ͨ͠ͱ͖ͷ
    ݕূ
    DIFDL νΣοΫϘοΫεͷ߲໨Λબ୒ͨ͠ͱ͖ͷݕূ
    VODIFDL νΣοΫϘοΫεͷ߲໨Λඇબ୒ʹͨ͠ͱ͖ͷݕূ
    BUUBDI ϑΝΠϧΠϯϓοτʹϑΝΠϧΛΞλονͨ͠ͱ͖ͷݕূ

    View full-size slide

  19. ศརπʔϧ
    • Laravel TestTools
    • Chrome extension
    • https://chrome.google.com/webstore/detail/
    laravel-testtools/
    ddieaepnbjhgcbddafciempnibnfnakl

    View full-size slide

  20. ศརπʔϧ
    ೖྗɾૢ࡞͢Δͱˠ
    ˡςετίʔυ͕ࣗಈͰੜ੒͞ΕΔ

    View full-size slide

  21. ·ͱΊ
    • Laravel͸ػೳςετ͕ॻ͖΍͍͢
    • ผύοέʔδʢbrowser-kit-testingʣʹͳ͕ͬͨɺศརͰ෼͔Γ΍͍͢API͕༻ҙ͞Ε͍ͯΔ
    • browser-kit-testingΛ࢖Θͳ͘ͱ΋͋Δఔ౓ͷAPI͸ຊମʹ࢒͍ͬͯΔ
    • ؆୯ͳDOMݕূ͘Β͍ͳΒͰ͖Δ͸ͣ
    • 5.4ʙͳΒDuskͱ͍͏બ୒΋͋Δ
    • ॻ͖΍͍͢ػೳςετ͔Β࢝ΊΔͱςετʹ׳ΕΔʢͱࢥ͏ʣ
    • ϓϩάϥϜΛΑΓৄࡉʹςετ͢Δίʔυʢ୯ମςετͱ͔ʣ͕ཉ͘͠ͳͬͯ͘Δ
    • ࣗવͱஈ֊తʹɹʢσόοάͱ͔܁Γฦ͍ͯ͠Δͱʣςετͷॻ͖ํ΍ඞཁੑΛମײ͢Δ
    • ςετ͕Θ͔Βͳ͚Ε͹·ͣػೳςετΛॻ͍ͯΈΔͷ͕ྑ͍͔΋͠Εͳ͍

    View full-size slide