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

Automated testing in Ruby 101

Automated testing in Ruby 101

Masafumi Okura

March 04, 2023
Tweet

More Decks by Masafumi Okura

Other Decks in Programming

Transcript

  1. RubyͰ͸͡ΊΔࣗಈςετ
    ࣛࣇౡRubyձٞ02


    େ૔խ࢙ʢOKURA Masafumiʣ
    2022-03-04, mark MEIZAN

    View full-size slide

  2. ࣗಈςετ

    View full-size slide

  3. ॻ͍͍ͯΔਓ—

    View full-size slide

  4. ࠓ೔ͷ໨ඪ

    View full-size slide

  5. ࣗಈςετ


    ʹ͍ͭͯͷ


    ֓ཁͷཧղ

    View full-size slide

  6. ࠓ೔ͷ͓࿩
    1. ࣗಈςετʹ͍ͭͯ


    2. Rubyʹ͓͚Δࣗಈςετ


    3. ྑ͍ࣗಈςετͱ͸


    4. ࣮ԋʂςετϑΝʔετ

    View full-size slide

  7. Okura.introduce(self)
    • ໊લɿେ૔խ࢙


    • ॴଐɿϑϦʔϥϯε


    • ՝֎׆ಈɿKaigi on RailsɺGrow.rbɺRubygems Code
    Reading෦ɺ֤छొஃɺOSS׆ಈɺRails GirlsίʔνɺϑΟ
    ϤϧυϒʔτΩϟϯϓͷΞυόΠβʔ


    • ॳࣛࣇౡ

    View full-size slide

  8. 1. ࣗಈςετ


    ʹ͍ͭͯ

    View full-size slide

  9. ࣗಈςετͱ͸

    View full-size slide

  10. ϓϩάϥϜͱͯ͠


    ࣮૷͞Εͨςετ

    View full-size slide

  11. ϓϩάϥϜͳͷͰ


    ࣗಈԽ͕؆୯

    View full-size slide

  12. ςετͳͷͰ


    ͋ΔछͷݕূΛ


    ߦ͏

    View full-size slide

  13. ࣗಈςετʹ͍ͭͯ
    1. ࣗಈςετͷԸܙ


    2. ࣗಈςετͷछྨ


    3. ࣗಈςετͷ஫ҙ఺

    View full-size slide

  14. 1.1 ࣗಈςετͷ


    Ըܙ

    View full-size slide

  15. ࣗಈςετ͸Կ͕خ͍͠ͷ͔ʁ
    • ίʔυʹର͢ΔυΩϡϝϯτʹͳΔ


    • ίʔυͷWhatΛઆ໌͢Δ


    • όάͷ࠶ൃʢϦάϨογϣϯʣΛ๷͙


    • ϦϑΝΫλϦϯάͷॿ͚ʹͳΔʢ΄΅ඞਢʣ


    • ʢςετΛઌʹॻ͘৔߹ʣίʔυͷ඼্࣭͕͕Δ


    • ʮςετϑΝʔετʯ

    View full-size slide

  16. 1.2 ࣗಈςετͷ


    छྨ

    View full-size slide

  17. ࣗಈςετͷछྨ
    • ୯ମςετʢϢχοτςετʣ


    • ଞͷίϯϙʔωϯτ͔Β੾Γ཭ͯ͠ςετ


    • ݁߹ςετ


    • ͍͔ͭ͘ͷίϯϙʔωϯτΛ૊Έ߹Θͤͯςετ

    View full-size slide

  18. 1.3 ࣗಈςετͷ


    ஫ҙ఺

    View full-size slide

  19. ࣗಈςετͰ஫ҙ͢΂͖͜ͱ
    • ʮόά͕ͳ͍ʯ͜ͱͷূ໌ʹ͸ͳΒͳ͍


    • ʮςετ͕௨ͬͨʂˠόάͬͯͨorzʯΈ͍ͨͳ͜ͱ΋
    Α͋͘Δ


    • ίʔυΛॻ͍͔ͯΒςετΛॻ͘ͱେมʹͳΓ͕ͪ


    • ςετϑΝʔετͷํָ͕ʢݸਓͷҙݟͰ͢ʣ

    View full-size slide

  20. ͜ͷ࣌఺Ͱ


    ఻͑ͯ


    ͓͖͍ͨ͜ͱ

    View full-size slide

  21. ࣗಈςετ͸


    ॻ͘΋ͷ

    View full-size slide

  22. ࣗಈςετ͸جຊతʹ͸ॻ͘
    • ʮςετϑΝʔετʯ͔ʮςετϥετʯ͔͸ͲͪΒͰ
    ΋Α͍


    • MiniTest͔RSpec͔͸ͲͪΒͰ΋Α͍


    • ࡉ͔͍͜ͱ΋ׂͱؾʹ͠ͳ͍ͰΑ͍


    • ͱʹ͔͘ॻ͘

    View full-size slide

  23. ॻ͔ͳ͍ޙչ


    ΑΓ


    ॻ͘ޙչ

    View full-size slide

  24. 2. Rubyʹ͓͚Δ


    ࣗಈςετ

    View full-size slide

  25. Rubyͷੈքʹ͸


    ͨ͘͞Μͷςετ


    gem͕͋Γ·͢

    View full-size slide

  26. ςετgemͷখ෼ྨ
    1. ςετϑϨʔϜϫʔΫ


    2. ಛఆ༻్޲͚DSL


    3. αϙʔτϥΠϒϥϦ

    View full-size slide

  27. 2.1 ςετ


    ϑϨʔϜϫʔΫ

    View full-size slide

  28. RubyͷςετϑϨʔϜϫʔΫ
    • RSpec


    • μ΢ϯϩʔυ਺͕࠷ଟɺ൚༻ςετDSLͰ΋͋Δ


    • MiniTest


    • xUnitܥ౷ɺεϐʔυͱγϯϓϧ͕͞΢Ϧ


    • Test::Unit


    • ࠷ݹͷςετϑϨʔϜϫʔΫɺxUnitܥ౷

    View full-size slide

  29. 2.2 ಛఆ༻్޲͚


    DSL

    View full-size slide

  30. ಛఆ༻్޲͚DSL
    • Capybara


    • ϒϥ΢βૢ࡞ͷͨΊͷDSL


    • Cucumber


    • ड͚ೖΕςετͷͨΊͷDSLɺ೔ຊޠ͕ॻ͚Δ

    View full-size slide

  31. 2.3 αϙʔτ


    ϥΠϒϥϦ

    View full-size slide

  32. αϙʔτϥΠϒϥϦ
    • FactoryBot


    • ςετσʔλʢߏ଄Խ͞Εͨσʔλʣͷੜ੒


    • Faker


    • ϥϯμϜσʔλʢϝʔϧΞυϨε΍໊લͳͲʣ


    • Timecop


    • ࣌ؒΛૢ࡞͢Δ

    View full-size slide

  33. 3. ྑ͍ࣗಈςετ


    ͱ͸

    View full-size slide

  34. ྑ͍ࣗಈςετͷϙΠϯτ
    • ࣗಈςετ͸ίʔυͳͷͰɺྑ͍ίʔυͷݪଇΛద༻͢Δ


    • Մಡੑʢ໋໊ɺཻ౓ͷখ͞͞ͳͲʣ


    • ద੾ͳߏ଄Խ


    • ࣮ߦ࣌ؒͷ୹͞


    • ແବͳσʔλੜ੒Λආ͚ΔʢಛʹσʔλϕʔεΞΫηε͸஗͍ʣ


    • ୯ମςετʹدͤΔʢ݁߹ςετ͸஗͍ʣ

    View full-size slide

  35. ࿦఺
    • RSpecͩͱྑ͍ςετʹ͍ͭͯٞ࿦ʹͳΓ͕ͪ


    • letͱlet!ͱbeforeͷ࢖͍෼͚


    • contextͱitʹ೔ຊޠΛ࢖͑Δ͔ʁ


    • etc…


    • ϩʔΧϧͳ׳शʹै͏ͷ͕٢

    View full-size slide

  36. 4. ࣮ԋʂ


    ςετϑΝʔετ

    View full-size slide