LoginSignup
18

More than 5 years have passed since last update.

PHPのモダンなテスティングフレームワークのCodeceptionを使ってみた

Last updated at Posted at 2015-10-16

Codeception?

  • フルスタックなテスティングフレームワーク
  • 単体テスト、機能テスト、受け入れテストをサポート
  • 内部はPHPUnit

あ、今回は受け入れテストのみやってみます。Seleniumと連携するまで。

composer.json
"require-dev": {
    "codeception/codeception": "*"
  }
composer update

準備!

./vendor/bin/codecept bootstrap

受け入れテスト作成

./vendor/bin/codecept generate:cept acceptance SignIn

できた。 /tests/acceptance/SignInCept.php

Seleniumインストール(Mac)

brew install selenium-server-standalone

Selenium起動

selenium-server
acceptance.suite.yml
class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
                 url: 'http://localhost/'
                 browser: firefox
SignIn.php
$I = new AcceptanceTester($scenario);

$I->wantTo('Sign In');
$I->amOnPage('/');
$I->fillField('userid', 'admin');
$I->fillField('password', 'admin');
$I->click('ログイン');
$I->see('ログインしました。');
./vendor/bin/codecept run

これでブラウザが起動して、フォームに入力して、ログインボタンクリックしたら何が表示されるかまでテストしてくれます。

Codeception PHP Testing Framework v2.1.3
Powered by PHPUnit 4.8.13 by Sebastian Bergmann and contributors.

Acceptance Tests (1) ------------------------------------------------------------------------------------------
Sign in (SignInCept)                                                                                      Ok
---------------------------------------------------------------------------------------------------------------


Time: 8.06 seconds, Memory: 11.50Mb

OK (1 test, 1 assertions)

参考

Codeception - BDD-style PHP testing.
http://codeception.com/

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18