testing with codeception (webelement #30)

20
Testing with CODECEPTION “boot your tests in PHP is a real pain” Adam Štipák | @new_POPE

Upload: adam-stipak

Post on 15-Jul-2015

484 views

Category:

Internet


3 download

TRANSCRIPT

Page 1: Testing with Codeception (Webelement #30)

Testing with

CODECEPTION“boot your tests in PHP is a real pain”

Adam Štipák | @new_POPE

Page 2: Testing with Codeception (Webelement #30)

Testing tools

● PHPUnit [https://phpunit.de/]

● Nette\Tester [http://tester.nette.org/en/]

● Simpletest [http://www.simpletest.org/]

● Testify.php [http://tutorialzine.com/projects/testify/]

● etc ...

Page 3: Testing with Codeception (Webelement #30)

Testing tools

Yes, they are really cool,but it is a little problem here.

Page 4: Testing with Codeception (Webelement #30)

Problem

LOW LEVEL

Page 5: Testing with Codeception (Webelement #30)

How can I set up other things?

● Selenium tests● API tests● Functional tests● Access to DB for check a state or setup prerequisities

● Data cleanup● and many, many things...

Page 6: Testing with Codeception (Webelement #30)

You can set up it manually,but WHY???

Page 7: Testing with Codeception (Webelement #30)

Just try CODECEPTION

Page 8: Testing with Codeception (Webelement #30)

Features● very fast setup● Unit (powered by PHPUnit)● API (REST, SOAP, XML-RPC)● Functional (Symfony2, Laravel, Yii, Zend)● Acceptance (PhpBrowser, Selenium)● Db (Db, Doctrine 1 & 2)● BDD - style readable tests● Modules & Addons !!!

Page 9: Testing with Codeception (Webelement #30)

Very fast setup - installation$ bin/composer.phar require “codeception/codeception:*”

$ vendor/bin/codeception bootstrap

$ .../codeception generate:cept acceptance Welcome

Page 10: Testing with Codeception (Webelement #30)

Very fast setup - write a test

// /tests/acceptance/WelcomeCept.php

$I = new AcceptanceTester($scenario);

$I->wantTo('ensure that frontpage works');

$I->amOnPage('/');

$I->see('Home');

Page 11: Testing with Codeception (Webelement #30)

Very fast setup - configure

// /tests/acceptance.suite.yml

class_name: AcceptanceGuy

modules:

enabled: [PhpBrowser, AcceptanceHelper]

# WebDriver instead of PhpBrowser for Selenium

config:

PhpBrowser:

url: '{YOUR APP'S URL}'

Page 12: Testing with Codeception (Webelement #30)

Very fast setup - run$ vendor/bin/codeception run

Suite acceptance started

Trying to ensure that frontpage works (WelcomeCept.php) - Ok

Suite functional started

Suite unit started

Time: 1 second, Memory: 21.00Mb

OK (1 test, 1 assertions)

Page 13: Testing with Codeception (Webelement #30)

API - config

class_name: ApiTester

modules:

enabled: [PhpBrowser, REST, ApiHelper]

config:

PhpBrowser:

url: http://serviceapp/

REST:

url: http://serviceapp/api/v1

Page 14: Testing with Codeception (Webelement #30)

API - test$I = new ApiTester($scenario);

$I->wantTo('create a user via API');

$I->haveHttpHeader('Content-Type',

'application/json');

$I->sendPOST('/users', ['name' => 'davert']);

$I->seeResponseCodeIs(201);

$I->seeResponseIsJson();

$I->seeResponseContains('{"result":"ok"}');

Page 15: Testing with Codeception (Webelement #30)

Db - configmodules:

enabled: [Db]

config:

Db:

dsn: 'mysql:host=localhost;dbname=testdb'

user: 'root'

password: ''

dump: 'tests/_data/dump.sql'

populate: true

cleanup: false

Page 16: Testing with Codeception (Webelement #30)

Db - test

$I->haveInDatabase('users', ['name' => 'miles']); //*

// $I->dontSeeInDatabase

$I->seeInDatabase('users', [

'name' => 'Davert',

'email' => '[email protected]'

]);

Page 17: Testing with Codeception (Webelement #30)

Modules & addons● PhpBrowser● Queue● REST● Redis● SOAP● Sequence● Silex● Symfony 1● Symfony 2● WebDriver● XMLRPC● Yii 1● Yii2● Zend 1 & 2

● AMQP● Asserts● Cli● Db● Dbh● Doctrine 1 & 2● FTP● Facebook● Filesystem● Kohana● Laravel4● Memcache● MongoDb● Phalcon1

Page 18: Testing with Codeception (Webelement #30)

Modules & addons● PhpBuiltinServer

● Phantoman

● and many others ...

Page 19: Testing with Codeception (Webelement #30)

FAQ

● how can I setup different URLs for REST?

● can I write OO oriented tests?

● what is interactive console?

● can I use DRY principle in tests (for login)?

Page 20: Testing with Codeception (Webelement #30)

Thanks

Adam Štipák | @new_POPE