code retreat codeception

12
Text クックビズ勉強会 (TDD)—>Test Driven Development > CodeCeption

Upload: florent-batard

Post on 12-Aug-2015

72 views

Category:

Software


0 download

TRANSCRIPT

Text

クックビズ勉強会(TDD)—>Test Driven Development > CodeCeption

CodeCeptionTest Framework

Acceptance Tests

Functional Tests

Unit Tests

一番簡単

Powered by PHPUnit -> standard

Yii2 modules

Selenium2 やPhantomJSと使える

例<?php $I = new AcceptanceTester($scenario); $I->wantTo('create wiki page'); $I->amOnPage('/'); $I->click('Pages'); $I->click('New'); $I->see('New Page'); $I->fillField('title', 'Hobbit'); $I->fillField('body', 'By Peter Jackson'); $I->click('Save'); $I->see('page created'); // notice generated $I->see('Hobbit','h1'); // head of page of is our title $I->seeInCurrentUrl('pages/hobbit'); $I->seeInDatabase('pages', array('title' => ‘Hobbit')); ?>

Different tests typeAcceptance

Tests

Functional Tests

Unit Tests

Yii2 BackendFrontend

Browser Selenium

PhantomJS

HTML

HTML

$_GET,$_POST,

$_REQUEST

Yii2 Module Backend

User Scenario

Developer Scenario

Function Testing

Acceptance Tests

Enable to do request and interact with the DOM

Use a fake browser to perform the queries

Can click and fill forms

Can be plugged with Selenium/PhantomJS to interact with JavaScript and screenshots

Functional Tests

Same as Acceptance test but does not use a browser engine

Can be plugged with the framework to access internal functions and properties (Models, validation)

Use $_REQUEST, $_POST and $_GET

Faster but less interaction

Unit TestsUsed to test functions Difficult to use in MVC Can be plugged with the framework to access internal functions and properties (Models, Validation)

public function testValidation() { $user = User::create(); $user->username = null; $this->assertFalse($user->validate(['username'])); $user->username = 'toolooooongnaaaaaaameeee'; $this->assertFalse($user->validate(['username'])); $user->username = 'davert'; $this->assertTrue($user->validate(['username'])); }

インストールMac OSX:

brew update && brew install codeception

Linux:

wget http://codeception.com/codecept.phar .

php codecept.phar bootstrap

Windows:

php composer.phar global require “codeception/codeception:*”

Composer/ PhpStorm:

php composer.phar require “codeception/codeception:*”

Getting readyBootStrap

>codecept bootstrap

>codecept generate:cept acceptance Validation

Edit the configuration file : tests/acceptance.suite.yml

class_name: AcceptanceTester

modules:

enabled:

- PhpBrowser

- AcceptanceHelper

config:

PhpBrowser:

url: 'https://foogent.jp/'

Let’s get the party started>codecept run

>codecept run —debug

Bonus

>codecept generate:scenarios acceptance //English version

>codecept console acceptance //Interactive console

>codecept run —debug —env test

ReferencesInstallation : http://codeception.com/install

Acceptance Tests : http://codeception.com/docs/04-AcceptanceTests

Yii2 module : http://codeception.com/docs/modules/Yii2

WebDriver : http://codeception.com/docs/modules/WebDriver

Yii2 Database Faker : http://qiita.com/tanakahisateru/items/c4d39cc77a71067ed658