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

Codeceptionでテストをしよう

 Codeceptionでテストをしよう

PHPカンファレンス福岡2016 LT
http://php-tips.com/2016/05/21/phpconfuk2016-lt-codeception/

Takashi Nojima

May 21, 2016
Tweet

More Decks by Takashi Nojima

Other Decks in Technology

Transcript

  1. Codeception!
    Ͱςετ͠Α͏
    .BZ
    1)1ΧϯϑΝϨϯε෱Ԭ

    View full-size slide

  2. About Me
    ໊લɿ໺ౡོʢͷ͡·͔ͨ͠ʣ
    ॴଐɿΠϥεςΟοΫίϯαϧλϯπגࣜձࣾ

    w CMPHIUUQQIQUJQTDPN
    w 5XJUUFS!OPKJNBHF

    View full-size slide

  3. ࿩͢͜ͱ
    w $PEFDFQUJPOͷ֓ཁ
    w σϞ
    w $FQUWT$FTU
    w ͓קΊϞδϡʔϧ

    View full-size slide

  4. Codeception ͱ͸

    View full-size slide

  5. Codeception ͱ͸
    wड͚ೖΕςετ "DDFQUBODF5FTU

    wػೳςετ 'VODUJPOBM5FTU

    w୯ମςετ 6OJU5FTU

    Λ·ͱΊͯॲཧͰ͖ΔςεςΟϯάϑϨʔϜϫʔΫ

    View full-size slide

  6. Codeception ͱ͸
    w ެࣜαΠτ

    IUUQDPEFDFQUJPODPN
    w ೔ຊޠυΩϡϝϯτ

    IUUQQJDDBHMJBOJHJUIVCJP$PEFDFQUJPOEPDTKB@+1

    View full-size slide

  7. Codeception ͷ͍͍ͱ͜Ζ
    8FC%SJWFSʹΑΔ+BWB4DSJQUͷڍಈΛؚΊͨςετΛ
    1)1Ͱॻ͚Δ
    ‣ ςετࣦഊ࣌ʹ͸ɺ)5.-΍εΫϦʔϯγϣοτΛ࢒ͯ͘͠ΕΔ
    ‣ 8FC%SJWFSʹ͸4FMFOJVNͷଞɺ1IBOUPN+4 8FC,JUϕʔεͷϔο
    υϨεϒϥ΢β
    ΋ར༻Մೳ

    View full-size slide

  8. ‣ -BSBWFM -VNFO
    ‣ 1IBMDPO
    ‣ 4JMFY
    ‣ 4ZNGPOZ
    ‣ :JJ
    ‣ ;FOE'SBNFXPSL
    ˞$BLF1)1͸ผ్Ϟδϡʔϧ
    ௥ՃͰରԠՄೳ
    ֤छϑϨʔϜϫʔΫΛඪ४αϙʔτ
    Codeception ͷ͍͍ͱ͜Ζ

    View full-size slide

  9. Codeception ͷ͍͍ͱ͜Ζ
    ‣ 3&45"1*ͷςετ༻Ϟδϡʔϧ͕͋Δ
    ‣ +40/Ͱ஋Λฦ͢"1*ͷςετ͕؆୯ʹॻ͚Δ

    View full-size slide

  10. ςετ Λॻ͍ͯΈΔ

    View full-size slide

  11. ͜Μͳͷ
    w πΠολʔͰʮQIQDPOGVLʯΛݕࡧ
    w ݕࡧ݁Ռʹʮ1)1ΧϯϑΝϨϯε࠷ߴʂʯ͕
    ؚ·Ε͍ͯΕ͹0,

    View full-size slide

  12. ςετίʔυ
    !
    $I = new AcceptanceTester($scenario);
    $I->wantTo('πΠολʔͰ #phpconfuk ΛݕࡧͰ͖Δ');
    !
    $I->amOnPage('/');
    $I->comment('ݕࡧϑΟʔϧυΛ։͍ͯೖྗ');
    $I->click('ݕࡧ');
    !
    $I->waitForElementVisible('#search-query');
    $I->fillField('#search-query', '#phpconfuk');
    $I->click('.StreamsTopBar-searchButton');
    $I->wait(3);
    !
    $I->expect('ݕࡧϖʔδ͕։͍͍ͯΔ');
    $I->seeCurrentUrlMatches('~^/search~');
    $I->seeInTitle('#phpconfuk');
    !
    $I->expect('݁Ռʹ"1)1ΧϯϑΝϨϯε࠷ߴʂ"ΛؚΜͰ͍Δ');
    $I->see('PHPΧϯϑΝϨϯε࠷ߴʂ', '#timeline');

    View full-size slide

  13. Cept vs Cest

    View full-size slide

  14. Cept
    !
    $I = new AcceptanceTester($scenario);
    $I->wantTo('log in as regular user');
    !
    $I->amOnPage('/login');
    $I->fillField('Username','davert');
    $I->fillField('Password','qwerty');
    $I->click('Login');
    !
    $I->see('Hello, davert');

    View full-size slide

  15. Cest
    !
    class LoginCest
    {
    !
    public function _before(AcceptanceTester $I)
    {
    }
    !
    public function _after(AcceptanceTester $I)
    {
    }
    !
    public function tryToTest(AcceptanceTester $I)
    {
    $I->wantTo('log in as regular user');
    !
    $I->amOnPage('/login');
    $I->fillField('Username', 'davert');
    $I->fillField('Password', 'qwerty');
    $I->click('Login');
    !
    $I->see('Hello, davert');
    }
    }

    View full-size slide

  16. Cept vs Cest
    $FTUͳΒ
    ‣ @CFGPSF
    @BGUFS
    ϝιουͰڞ௨ͷલॲཧʗ
    ޙॲཧ͕هड़Մೳ
    ‣ ΞϊςʔγϣϯͰςετέʔεͷάϧʔϓԽ΍ґ
    ଘؔ܎Λهड़Մೳ

    View full-size slide

  17. ͓קΊϞδϡʔϧ

    View full-size slide

  18. ͓קΊϞδϡʔϧ
    w TJUFQIBOUPNBO
    w KBLPDIQIBOUPNKTJOTUBMMFS
    w DBQUCBSJUPOFNBJMDBUDIFSDPEFDFQUJPONPEVMF
    w NBJMDBUDIFSμϛʔ4.51αʔόΛ্ཱͪ͛ΕΔHFN

    View full-size slide

  19. ϚϧνόΠτ΁ͷରԠ
    ಺෦ͰTVCTUS౳ͷϚϧνόΠτະରԠͷؔ਺Λ࢖
    ༻͍ͯ͠Δ
    ‣ ςετͷϝιου໊΍ϝοηʔδʹϚϧνόΠ
    τจࣈΛ࢖༻ͨ͠৔߹͸දࣔ΍ಈ࡞่͕ΕΔ

    View full-size slide

  20. IDEͷରԠ
    w /FU#FBOT͔ΒରԠ
    w 1)14UPSNϓϥάΠϯͰରԠ
    w IUUQTHJUIVCDPNUJHFSTFPDPEFDFQUJPOQIQTUPSN
    DPNNBOEMJOFUPPM

    View full-size slide

  21. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide