SlideShare une entreprise Scribd logo
1  sur  23
Télécharger pour lire hors ligne
CodeCeption
introduction and use in Yii
Yii London Meetup - 15 April 2014
by Matteo ‘Peach’ Pescarin - @ilPeach
CodeCeption introduction and use in Yii
The current situation
(Potentially) fiddly system configuration
unless
the framework ships a testing environment
e.g.
db connection,
access to magic functions,
autoloading functionality,
...
CodeCeption introduction and use in Yii
Yet another tool?
NOPE
It’s been designed to ease the testing process.
It’s meant to be extensible and modular.
Creates uniformity across different test suites.
Works on top of other well known technologies,
e.g. PHPUnit, PHPBrowser, Selenium, etc...
CodeCeption introduction and use in Yii
Should you bother writing tests?
YES
CodeCeption introduction and use in Yii
Should you bother writing tests?
Yes, you really should.
And no, you don’t need to test everything.
You need a QA strategy,
which comes with proper planning
and a desire to avoid spending the weekend fixing bugs.
Unless you’re a maniac
who loves to deliver buggier code in production.
CodeCeption introduction and use in Yii
What kind of tests?
Acceptance High-level tests, can have no knowledge of the technologies used.
Testing done from the non-technical person PoV (called WebGuy):
“uses the browser to test the website works correctly.”
Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,..
CodeCeption introduction and use in Yii
What kind of tests?
Acceptance High-level tests, can have no knowledge of the technologies used.
Testing done from the non-technical person PoV (called WebGuy):
“uses the browser to test the website works correctly.”
Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,..
Functional Mid-level tests. Covers functionality from the server perspective.
The person testing (called TestGuy) knows how the application works, passes
different $_GET, $_POST and $_REQUEST variables to ensure the functionality
covers all known and corner cases.
Simpler than Acceptance, does not need a webserver, uses PHPBrowser.
CodeCeption introduction and use in Yii
What kind of tests?
Acceptance High-level tests, can have no knowledge of the technologies used.
Testing done from the non-technical person PoV (called WebGuy):
“uses the browser to test the website works correctly.”
Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,..
Functional
Unit
Mid-level tests. Covers functionality from the server perspective.
The person testing (called TestGuy) knows how the application works, passes
different $_GET, $_POST and $_REQUEST variables to ensure the functionality
covers all known and corner cases.
Simpler than Acceptance, does not need a webserver, uses PHPBrowser.
Low-level tests. Single isolated tests.
The person testing, CodeGuy, knows the internals of the application and tests
database operations and anything else that might need proof of concept.
Packages PHPUnit and provides a further abstraction over it to simplify its use.
CodeCeption introduction and use in Yii
Preliminary steps in Yii2
using the Yii2-app-base, read /tests/README.md first:
$ composer require --dev "codeception/codeception: 1.8.*@dev" 
"codeception/specify: *" 
"codeception/verify: *"
Then run the build script in order to populate the missing bits
$ vendor/bin/codecept build
Building Guy classes for suites: functional, acceptance, unit
TestGuy includes modules: Filesystem, TestHelper, Yii2
TestGuy.php generated successfully. 53 methods added
WebGuy includes modules: WebHelper, PhpBrowser
WebGuy.php generated successfully. 48 methods added
CodeGuy includes modules: CodeHelper
CodeGuy.php generated successfully. 1 methods added
CodeCeption introduction and use in Yii
Configure your entry URLs
configure the TEST_ENTRY_URL variable in tests/_boostrap.php
$ grep TEST_ENTRY_URL tests/_bootstrap.php
defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/web/index-test.php');
$_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL;
Set the URL for the acceptance tests (based on the module you want to use)
$ grep -B1 url tests/acceptance.suite.yml
PhpBrowser:
url: 'http://sandbox/yii2-test/'
# WebDriver:
# url: 'http://localhost'
CodeCeption introduction and use in Yii
Implement and run the tests
Generate and implement the tests in the template given:
$ vendor/bin/codecept generate:cept acceptance Homepage
Test was created in HomepageCept.php
$ vim tests/acceptance/HomepageCept.php
Run the tests!
$ vendor/bin/codecept run
[snip]
OK (13 tests, 63 assertions)
$
CodeCeption introduction and use in Yii
Acceptance tests using PHPBrowser
BDD scenarios can be easily translated into acceptance tests, e.g.:
“As an account holder
I want to be able to login
so I can check my dashboard”
CodeCeption introduction and use in Yii
A “practical” example
<?php
$I = new WebGuy($scenario);
$I->wantTo(‘login to check the
dashboard’);
$I->amOnPage(‘/’);
$I->see(‘Yii2 test’);
$I->seeLink(‘login’, ‘site/login’);
$I->click(‘login’);
$I->see(‘Login’, ‘h1’);
// fillField() on the form
$I->click(‘login-button’);
$I->seeLink(‘Logout (admin)’);
$I->see(‘Admin dashboard’);
“As an account holder
I want to be able to login
so I can check my dashboard”
CodeCeption introduction and use in Yii
Very similar to each other in terms of commands, but...
Acceptance tests can run cross-browser compatibility
checks using Selenium Webdriver, ZombieJS, etc
Functional are simpler and more straight forward to
implement.
Functional are good for testing APIs and REST interfaces.
The Goutte engine in functional does not know how to JS!
Acceptance vs Functional tests
CodeCeption introduction and use in Yii
So what about Yii1?
❖ Functional tests using Selenium RC.
❖ Unit tests using PHPUnit (via PEAR).
Since PHPUnit >= 3.6 and the Composer Revolution,
things started to go awry.
Yii’s autoloaders and the new PHPUnit’s don’t fit together.
Cannot take full advantage of newest Selenium Webdriver.
CodeCeption introduction and use in Yii
Using CodeCeption in Yii1
follow the CodeCeption quickstart guide (http://codeception.com/quickstart)
$ mkdir protected/vendor/bin && cd protected/vendor/bin
$ wget http://codeception.com/codecept.phar && chmod a+x codecept.phar
Initialise the directory structure
$ cd protected/ && vendor/bin/codecept.phar bootstrap
Initializing Codeception in /mnt/workspace/yii1-test/protected
[snip]
Bootstrap is done. Check out /mnt/workspace/yii1-test/protected/tests directory
$
CodeCeption introduction and use in Yii
Additional modules and configuration
install the Yii1 CodeCeption Bridge (https://github.com/Codeception/YiiBridge)
$ git clone git@github.com:Codeception/YiiBridge.git tests/_data/YiiBridge
$ echo "require_once __DIR__.'/_data/YiiBridge/yiit.php';" >> tests/_bootstrap.php
Configure your tests/<type>.suite.yaml file(s) and add Yii1, configuring it:
class_name: MyGuy
modules:
enabled: [Yii1, Filesystem, MyHelper]
config:
Yii1:
appPath: '/mnt/workspace/yii1-test/index-test.php'
url: 'http://sandbox/yii1-test/index-test.php'
CodeCeption introduction and use in Yii
$ vendor/bin/codecept.phar build
Building Guy classes for suites: functional, acceptance, unit
Build and run
Re-run the build script now that Yii1 has been setup.
This is needed for any change made on the yaml files.
Create and implement your tests and run the suite(s)
$ vendor/bin/codecept.phar generate:cept functional Homepage
Test was created in HomepageCept.php
$ vim tests/functional/HomepageCept.php
$ vendor/bin/codecept.phar run functional
CodeCeption introduction and use in Yii
Few notes on Unit tests
CodeCeption unit tests won’t be available, but PHPUnit:
$ vendor/bin/codecept.phar generate:phpunit unit LoginForm
Test was created in /mnt/workspace/yii1-test/protected/tests/unit/LoginFormTest.php
When creating the tests you need to adjust the extended class to be:
class LoginFormTest extends CTestCase # or CDbTestCase
{
If using CDbTestCase, remember to call the parent classes’ in the setUp() and
tearDown() methods to make fixtures work as expected.
CodeCeption introduction and use in Yii
Other cool stuff
❖ Interactive console
❖ Grouping
❖ Dependencies
❖ Cest classes
❖ PageObjects
❖ StepObjects
❖ Environments
CodeCeption introduction and use in Yii
Some live examples and Q&A
CodeCeption introduction and use in Yii
Now, go and test stuff!
and when in doubt:
read the generated code (e.g. Guys, Pages, etc...)
check the documentation of CodeCeption:
http://codeception.com
and its integration into Yii2:
http://www.yiiframework.com/doc-2.0/ext-codeception-index.html
Thank you for listening!
Yii London Meetup - 15 April 2014
Matteo ‘Peach’ Pescarin
@ilPeach
http://peach.smartart.it

Contenu connexe

Tendances

Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesVijay Rangaiah
 
05 junit
05 junit05 junit
05 junitmha4
 
Py.test
Py.testPy.test
Py.testsoasme
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
짝 테스트(Pair Testing) 소개와 사례
짝 테스트(Pair Testing) 소개와 사례짝 테스트(Pair Testing) 소개와 사례
짝 테스트(Pair Testing) 소개와 사례SangIn Choung
 
우아한테크세미나-우아한멀티모듈
우아한테크세미나-우아한멀티모듈우아한테크세미나-우아한멀티모듈
우아한테크세미나-우아한멀티모듈용근 권
 
Selenium C# - The Essential Test Automation Guide
Selenium C# - The Essential Test Automation GuideSelenium C# - The Essential Test Automation Guide
Selenium C# - The Essential Test Automation GuideRapidValue
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introMaurice De Beijer [MVP]
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental PrinciplesIntro C# Book
 
Selenium
SeleniumSelenium
Seleniumeduquer
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in AngularKnoldus Inc.
 

Tendances (20)

Selenium Presentation at Engineering Colleges
Selenium Presentation at Engineering CollegesSelenium Presentation at Engineering Colleges
Selenium Presentation at Engineering Colleges
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
05 junit
05 junit05 junit
05 junit
 
Py.test
Py.testPy.test
Py.test
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
Java Basics
Java BasicsJava Basics
Java Basics
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
짝 테스트(Pair Testing) 소개와 사례
짝 테스트(Pair Testing) 소개와 사례짝 테스트(Pair Testing) 소개와 사례
짝 테스트(Pair Testing) 소개와 사례
 
우아한테크세미나-우아한멀티모듈
우아한테크세미나-우아한멀티모듈우아한테크세미나-우아한멀티모듈
우아한테크세미나-우아한멀티모듈
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
 
An introduction to Vue.js
An introduction to Vue.jsAn introduction to Vue.js
An introduction to Vue.js
 
Selenium C# - The Essential Test Automation Guide
Selenium C# - The Essential Test Automation GuideSelenium C# - The Essential Test Automation Guide
Selenium C# - The Essential Test Automation Guide
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles20. Object-Oriented Programming Fundamental Principles
20. Object-Oriented Programming Fundamental Principles
 
Selenium
SeleniumSelenium
Selenium
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Unit Testing in Angular
Unit Testing in AngularUnit Testing in Angular
Unit Testing in Angular
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 

En vedette

Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with CodeceptionJeremy Coates
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Joe Ferguson
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Joe Ferguson
 

En vedette (7)

Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with Codeception
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
 
Testování prakticky
Testování praktickyTestování prakticky
Testování prakticky
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
 
X-Debug in Php Storm
X-Debug in Php StormX-Debug in Php Storm
X-Debug in Php Storm
 
Yii framework
Yii frameworkYii framework
Yii framework
 

Similaire à Codeception introduction and use in Yii

Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsArtur Babyuk
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Testing in Craft CMS
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMSJustinHolt20
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appiumPratik Patel
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHPMarcos Quesada
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With SeleniumJodie Miners
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Puneet Kala
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Deliverymasoodjan
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Yves Hoppe
 
How to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated TestingHow to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated TestingAcquia
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with SeleniumDave Haeffner
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsDana Luther
 

Similaire à Codeception introduction and use in Yii (20)

Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Testing in Craft CMS
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMS
 
Codeception
CodeceptionCodeception
Codeception
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
Testing In Java4278
Testing In Java4278Testing In Java4278
Testing In Java4278
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
 
Mayur_Resume (2) (1)
Mayur_Resume (2) (1)Mayur_Resume (2) (1)
Mayur_Resume (2) (1)
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Bridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous DeliveryBridging the communication Gap & Continuous Delivery
Bridging the communication Gap & Continuous Delivery
 
Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016Joomla! Testing - J!DD Germany 2016
Joomla! Testing - J!DD Germany 2016
 
How to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated TestingHow to Build and Maintain Quality Drupal Sites with Automated Testing
How to Build and Maintain Quality Drupal Sites with Automated Testing
 
Getting Started with Selenium
Getting Started with SeleniumGetting Started with Selenium
Getting Started with Selenium
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Code Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application MigrationsCode Coverage for Total Security in Application Migrations
Code Coverage for Total Security in Application Migrations
 

Dernier

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Dernier (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Codeception introduction and use in Yii

  • 1. CodeCeption introduction and use in Yii Yii London Meetup - 15 April 2014 by Matteo ‘Peach’ Pescarin - @ilPeach
  • 2. CodeCeption introduction and use in Yii The current situation (Potentially) fiddly system configuration unless the framework ships a testing environment e.g. db connection, access to magic functions, autoloading functionality, ...
  • 3. CodeCeption introduction and use in Yii Yet another tool? NOPE It’s been designed to ease the testing process. It’s meant to be extensible and modular. Creates uniformity across different test suites. Works on top of other well known technologies, e.g. PHPUnit, PHPBrowser, Selenium, etc...
  • 4. CodeCeption introduction and use in Yii Should you bother writing tests? YES
  • 5. CodeCeption introduction and use in Yii Should you bother writing tests? Yes, you really should. And no, you don’t need to test everything. You need a QA strategy, which comes with proper planning and a desire to avoid spending the weekend fixing bugs. Unless you’re a maniac who loves to deliver buggier code in production.
  • 6. CodeCeption introduction and use in Yii What kind of tests? Acceptance High-level tests, can have no knowledge of the technologies used. Testing done from the non-technical person PoV (called WebGuy): “uses the browser to test the website works correctly.” Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,..
  • 7. CodeCeption introduction and use in Yii What kind of tests? Acceptance High-level tests, can have no knowledge of the technologies used. Testing done from the non-technical person PoV (called WebGuy): “uses the browser to test the website works correctly.” Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,.. Functional Mid-level tests. Covers functionality from the server perspective. The person testing (called TestGuy) knows how the application works, passes different $_GET, $_POST and $_REQUEST variables to ensure the functionality covers all known and corner cases. Simpler than Acceptance, does not need a webserver, uses PHPBrowser.
  • 8. CodeCeption introduction and use in Yii What kind of tests? Acceptance High-level tests, can have no knowledge of the technologies used. Testing done from the non-technical person PoV (called WebGuy): “uses the browser to test the website works correctly.” Can be plugged into different testing suites: e.g. PHPBrowser, Selenium, Sahi,.. Functional Unit Mid-level tests. Covers functionality from the server perspective. The person testing (called TestGuy) knows how the application works, passes different $_GET, $_POST and $_REQUEST variables to ensure the functionality covers all known and corner cases. Simpler than Acceptance, does not need a webserver, uses PHPBrowser. Low-level tests. Single isolated tests. The person testing, CodeGuy, knows the internals of the application and tests database operations and anything else that might need proof of concept. Packages PHPUnit and provides a further abstraction over it to simplify its use.
  • 9. CodeCeption introduction and use in Yii Preliminary steps in Yii2 using the Yii2-app-base, read /tests/README.md first: $ composer require --dev "codeception/codeception: 1.8.*@dev" "codeception/specify: *" "codeception/verify: *" Then run the build script in order to populate the missing bits $ vendor/bin/codecept build Building Guy classes for suites: functional, acceptance, unit TestGuy includes modules: Filesystem, TestHelper, Yii2 TestGuy.php generated successfully. 53 methods added WebGuy includes modules: WebHelper, PhpBrowser WebGuy.php generated successfully. 48 methods added CodeGuy includes modules: CodeHelper CodeGuy.php generated successfully. 1 methods added
  • 10. CodeCeption introduction and use in Yii Configure your entry URLs configure the TEST_ENTRY_URL variable in tests/_boostrap.php $ grep TEST_ENTRY_URL tests/_bootstrap.php defined('TEST_ENTRY_URL') or define('TEST_ENTRY_URL', '/web/index-test.php'); $_SERVER['SCRIPT_NAME'] = TEST_ENTRY_URL; Set the URL for the acceptance tests (based on the module you want to use) $ grep -B1 url tests/acceptance.suite.yml PhpBrowser: url: 'http://sandbox/yii2-test/' # WebDriver: # url: 'http://localhost'
  • 11. CodeCeption introduction and use in Yii Implement and run the tests Generate and implement the tests in the template given: $ vendor/bin/codecept generate:cept acceptance Homepage Test was created in HomepageCept.php $ vim tests/acceptance/HomepageCept.php Run the tests! $ vendor/bin/codecept run [snip] OK (13 tests, 63 assertions) $
  • 12. CodeCeption introduction and use in Yii Acceptance tests using PHPBrowser BDD scenarios can be easily translated into acceptance tests, e.g.: “As an account holder I want to be able to login so I can check my dashboard”
  • 13. CodeCeption introduction and use in Yii A “practical” example <?php $I = new WebGuy($scenario); $I->wantTo(‘login to check the dashboard’); $I->amOnPage(‘/’); $I->see(‘Yii2 test’); $I->seeLink(‘login’, ‘site/login’); $I->click(‘login’); $I->see(‘Login’, ‘h1’); // fillField() on the form $I->click(‘login-button’); $I->seeLink(‘Logout (admin)’); $I->see(‘Admin dashboard’); “As an account holder I want to be able to login so I can check my dashboard”
  • 14. CodeCeption introduction and use in Yii Very similar to each other in terms of commands, but... Acceptance tests can run cross-browser compatibility checks using Selenium Webdriver, ZombieJS, etc Functional are simpler and more straight forward to implement. Functional are good for testing APIs and REST interfaces. The Goutte engine in functional does not know how to JS! Acceptance vs Functional tests
  • 15. CodeCeption introduction and use in Yii So what about Yii1? ❖ Functional tests using Selenium RC. ❖ Unit tests using PHPUnit (via PEAR). Since PHPUnit >= 3.6 and the Composer Revolution, things started to go awry. Yii’s autoloaders and the new PHPUnit’s don’t fit together. Cannot take full advantage of newest Selenium Webdriver.
  • 16. CodeCeption introduction and use in Yii Using CodeCeption in Yii1 follow the CodeCeption quickstart guide (http://codeception.com/quickstart) $ mkdir protected/vendor/bin && cd protected/vendor/bin $ wget http://codeception.com/codecept.phar && chmod a+x codecept.phar Initialise the directory structure $ cd protected/ && vendor/bin/codecept.phar bootstrap Initializing Codeception in /mnt/workspace/yii1-test/protected [snip] Bootstrap is done. Check out /mnt/workspace/yii1-test/protected/tests directory $
  • 17. CodeCeption introduction and use in Yii Additional modules and configuration install the Yii1 CodeCeption Bridge (https://github.com/Codeception/YiiBridge) $ git clone git@github.com:Codeception/YiiBridge.git tests/_data/YiiBridge $ echo "require_once __DIR__.'/_data/YiiBridge/yiit.php';" >> tests/_bootstrap.php Configure your tests/<type>.suite.yaml file(s) and add Yii1, configuring it: class_name: MyGuy modules: enabled: [Yii1, Filesystem, MyHelper] config: Yii1: appPath: '/mnt/workspace/yii1-test/index-test.php' url: 'http://sandbox/yii1-test/index-test.php'
  • 18. CodeCeption introduction and use in Yii $ vendor/bin/codecept.phar build Building Guy classes for suites: functional, acceptance, unit Build and run Re-run the build script now that Yii1 has been setup. This is needed for any change made on the yaml files. Create and implement your tests and run the suite(s) $ vendor/bin/codecept.phar generate:cept functional Homepage Test was created in HomepageCept.php $ vim tests/functional/HomepageCept.php $ vendor/bin/codecept.phar run functional
  • 19. CodeCeption introduction and use in Yii Few notes on Unit tests CodeCeption unit tests won’t be available, but PHPUnit: $ vendor/bin/codecept.phar generate:phpunit unit LoginForm Test was created in /mnt/workspace/yii1-test/protected/tests/unit/LoginFormTest.php When creating the tests you need to adjust the extended class to be: class LoginFormTest extends CTestCase # or CDbTestCase { If using CDbTestCase, remember to call the parent classes’ in the setUp() and tearDown() methods to make fixtures work as expected.
  • 20. CodeCeption introduction and use in Yii Other cool stuff ❖ Interactive console ❖ Grouping ❖ Dependencies ❖ Cest classes ❖ PageObjects ❖ StepObjects ❖ Environments
  • 21. CodeCeption introduction and use in Yii Some live examples and Q&A
  • 22. CodeCeption introduction and use in Yii Now, go and test stuff! and when in doubt: read the generated code (e.g. Guys, Pages, etc...) check the documentation of CodeCeption: http://codeception.com and its integration into Yii2: http://www.yiiframework.com/doc-2.0/ext-codeception-index.html
  • 23. Thank you for listening! Yii London Meetup - 15 April 2014 Matteo ‘Peach’ Pescarin @ilPeach http://peach.smartart.it