SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Codeception
ACCEPTANCE
TESTING
Selenium WebDriver, PhpBrowser.
Data cleanup.
Continuous Integration.
Remote Code Coverage.
Symfony2, Laravel, Yii, Phalcon,
Zend Framework, Kohana,
Databases, REST, SOAP, CodeCoverage
FUNCTIONAL TESTING
API TESTING
REST, SOAP, XML-RPC
via PHPBrowser or PHP
Frameworks.
BDD-style PHP Testing
BDD的重點是通過與利益相關者的討論取
得對預期的軟體行為的清晰認識。它通過
用自然語言書寫非程式設計師可讀的測試
用例擴展了測試驅動開發方法。
開發者得以把精力集中在代碼應該怎
麼寫,而不是技術細節上,而且也最大程
度的減少了將代碼編寫者的技術語言與商
業客戶、用戶、利益相關者、專案管理者
等的領域語言之間來回翻譯的代價。
ACCEPTANCE TESTING
This scenario can be performed either
by a
simple PHP browser or by a browser
with
Selenium WebDriver.
Acceptance testing can be
performed by a non-technical person.
You can reproduce a
AcceptanceTester‘s actions in
scenarios and run them
automatically after each site change.
Generated scenarios will be stored in
your _data directory in text files.
PHP BROWSER
This is the fastest way to run acceptance tests, since it doesn't require running an
actual browser. We use a PHP web scrapper, which acts like a browser:
it sends a request, then receives and parses the response.
Before we start we need a local copy of
the site running on your host.
We need to specify the url parameter in the
acceptance suite config
(tests/acceptance.suite.yml).
Get Start
start by creating a 'Cept' file in the tests/acceptance directory.
Let's call it SigninCept.php
The wantTo section describes
your scenario in brief.
The $I object is used to write all
interactions.
The methods of the $I object are
taken from thePHPBrowser and Db
modules.If you have ever written a BDD scenario in Gherkin,
you can write a classic feature story:
CLICK
Emulates a click on valid anchors
As a parameter you can specify
the link name or a valid CSS or
XPath selector.
You can specify locator type manually
by passing array as a parameter.
We call this a strict locator. Available strict locator types are:
• id
• name
• css
• xpath
• link
• class
SEELINK
Before clicking the link you can
perform a check if the link really
exists on a page. This can be
done by the seeLink action
FORMS
Let's submit this sample form inside the Codeception test.
Rewitten scenarioTesting scenario
AJAX EMULATION
PHP browser can't process JavaScript. Still, all the ajax calls can be easily
emulated
by sending the proper requests to the server.
ASSERTIONS
Test the page contents
The most useful command for this is see.
check that specific element exists (or not) other useful commands to perform checks.
Please note that they all start with the see prefix.
CONDITIONAL ASSERTIONS
Sometimes you don't want the test to be stopped when an assertion fails
Maybe you have a long-running test and you want it to run to the end
REPLACEMENT :
see => canSee
dontSee => cantSee
GRABBERS
These commands retrieves data that can be used in test.
Imagine, your site generates a password for every user and you want to
check the user can log into the site using this password.
Grabbers allow you to get a single value from the current page with
commands.
COMMENTS
Commands like amGoingTo, expect , expectTo helps you in making
tests
COOKIES, URLS, TITLE, ETC
SELENIUM WEBDRIVER
Most scenarios can be easily ported between the testing backends
Your PhpBrowser tests we wrote previously can be executed inside a
real browser (or even PhantomJS) with Selenium WebDriver.
Change
reconfigure and rebuild the AcceptanceTester class,
to use WebDriver instead of PhpBrowser.
SELENIUM WEBDRIVER
In order to run Selenium tests you need to download Selenium Server and
get it running (Alternatively you may use PhantomJS headless browser
in ghostdriver mode).
If you run acceptance tests with Selenium, Firefox will be started and all actions
will
be performed step by step using browser engine.
In this case seeElement won't just check that the element exists on a page, but it
will
also check that element is actually visible to user.
WAIT
While testing web application, you may need to wait for JavaScript events
to occur.
Due to its asynchronous nature, complex JavaScript interactions are hard
to test.
MULTI SESSION TESTING
Codeception allows you to execute actions in concurrent session. The
most obvious
case for it - testing realtime messaging between users on site.
In order to do it you will need to launch 2 browser windows in a same time
for the
same test. Codeception has very smart concept for doing this. It is called
Friends.
CLEANING THINGS UP
While testing, your actions may change the data on the site. Tests will fail if
trying to
create or update the same data twice.
To avoid this problem, your database should be repopulated for each test.
To make repopulation work, create an sql dump of your database and put it
into the
/tests/_data directory
DEBUGGING
Codeception modules can print valuable information while running.
Just execute tests with the --debug option to see running details.
For any custom output use codecept_debug function.
On each fail, the snapshot of the last shown page will be stored in the
tests/_log
directory.
PHPBrowser will store html code and WebDriver will save the screenshot of a
page.
ACCEPTANCE TESTING
Selenium WebDriver, PhpBrowser.
Data cleanup.
Continuous Integration.
Remote CodeCoverage.
Symfony2, Laravel, Yii, Phalcon,
Zend Framework, Kohana,
Databases, REST, SOAP, CodeCoverage
FUNCTIONAL TESTING
API TESTING
REST, SOAP, XML-RPC
via PHPBrowser or PHP
Frameworks.
FUNCTIONAL TESTS
Functional tests don't require a web server to run tests.
In simple terms we set $_REQUEST, $_GET and$_POST variables then we
execute
application from a test.
Modules for all of these frameworks share the same interface, and thus
your tests
are not bound to any one of them. This is a sample functional test.
As you see you can use same tests for functional and acceptance testing.
PITFALLS
less stable
Headers, Cookies, Sessions
One of the common issues problems with functional tests are usage of PHP
functions
that deal with headers, sessions, cookies.
For instance, Header function triggers an error if it is executed more then once.
In functional tests, we run application multiple times thus, we will get lots of
trash errors in
the result.
Shared Memory
PHP application does not stop after it finished processing a request
As all requests run in one memory container they are not isolated.
So if you see that your tests are mysteriously failing when they shouldn't –
try to execute a single test.
ENABLING FRAMEWORK MODULES
Symfony2
Just need to include the Symfony2 module into your test suite.
If you also use Doctrine2, don't forget to include it either.
By default this module will search for App Kernel in the app directory.
The module uses the Symfony Profiler to provide additional information
and assertions.
LARAVEL 4
YII
YII2
Yii2 tests are included in Basic and Advanced application templates.
Follow Yii2 guides to start.
By itself Yii framework does not have an engine for functional testing.
So Codeception is the first and only functional testing framework for Yii.
To use it with Yii include Yii1 module into config.
Zend Framework 2
Zend Framework 1.x
The module for Zend Framework is highly inspired by ControllerTestCase
class, used
for functional testing with PHPUnit.
It follows similar approaches for bootstrapping and cleaning up.
To start using Zend Framework in your functional tests, include the ZF1
module.
Phalcon 1.x
Phalcon1 module requires creating bootstrap file which returns instance of
PhalconMvcApplication.
To start functional tests with Phalcon you should enable Phalon1 module
and provid
path to this bootstrap file:
WRITING FUNCTIONAL TESTS
Functional tests are written in the same manner as Acceptance Tests with
PhpBrowser module enabled.
Click
submit form
Aassertion
Framework modules
Access framework globals inside a test or access
Depenency
Injection containers inside FunctionalHelper class.
ERROR REPORTING
Uses E_ALL & ~E_STRICT & ~E_DEPRECATED error reporting value
In functional tests you might want to change this values depending on
framework's error policy.
error_level can be set globally in codeception.yml file.
ACCEPTANCE TESTING
Selenium WebDriver, PhpBrowser.
Data cleanup.
Continuous Integration.
Remote CodeCoverage.
Symfony2, Laravel, Yii, Phalcon,
Zend Framework, Kohana,
Databases, REST, SOAP, CodeCoverage
FUNCTIONAL TESTING
API TESTING
REST, SOAP, XML-RPC
via PHPBrowser or PHP
Frameworks.
UNIT TESTS
Codeception uses PHPUnit as a backend for running tests. Thus, any
PHPUnit test
can be added to Codeception test suite and then executed.
If you ever wrote a PHPUnit test then do it just as you did before.
Codeception adds
some nice helpers to simplify common tasks.
To say it again: you don't need to install PHPUnit to run its tests.
Codeception can run
them too.
CREATING TEST
Nice generators to simplify test creation.
start with generating a classical PHPUnit test extending
PHPUnit_Framework_TestCase class
Need another command to create Codeception-powered unit test
Both tests will create a new ExampleTest file located in tests/unit directory.
A test created by generate:test command will look like this:
Has predefined _before and _after methods to start with.
Use them to create a tested object before each test, and destroy it
afterwards.
BDD SPECIFICATION TESTING
For this case we have a stand-alone project Specify(included in phar
package) for writing specifications inside a unit test.
USING MODULES
As in scenario-driven functional or acceptance tests you can access actor
class
methods.
If you write integration tests, it may be useful to include Db module for
database
testing.
To access UnitTester methods you can use UnitTester property in a test.
TESTING DATABASE
Database will be cleaned and populated after each test, as it happens for
acceptance
and functional tests.
If it's not your required behavior, please change the settings of Db module
for current
suite.
ACCESSING MODULE
Codeception allows you to access properties and methods of all modules
defined for
this suite.
Unlike using the UnitTester class for this purpose, using module directly
grants you
access to all public properties of that module.
All public variables are listed in references for corresponding modules.
CEST
Alternatively to testcases extended from PHPUnit_Framework_TestCase
you may use
Codeception-specific Cest format.
It does not require to be extended from any other class.
All public methods of this class is a test.
The example above can be rewritten in scenario-driven manner like this:
For unit testing you may include Asserts module, that adds regular
assertions to
UnitTester which we access from $t variable.
STUBS
Codeception provides a tiny wrapper over PHPUnit mocking framework to
create stubs
easily. Include CodeceptionUtilStub to start creating dummy objects.
In this example we instantiate object without calling a constructor and
replace
getName method to return jon value.
Stubs are created with PHPUnit's mocking framework. Alternatively you can
use
Mockery (with Mockery module), AspectMock or others.

Más contenido relacionado

La actualidad más candente

Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghEngineor
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with CodeceptionJeremy Coates
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Cogapp
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.David Aguilera
 
CI / CD w/ Codeception
CI / CD w/ CodeceptionCI / CD w/ Codeception
CI / CD w/ CodeceptionTudor Barbu
 
Testing PHP with Codeception
Testing PHP with CodeceptionTesting PHP with Codeception
Testing PHP with CodeceptionJohn Paul Ada
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Adam Štipák
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersAjit Jadhav
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction SheetvodQA
 
Top trending selenium interview questions
Top trending selenium interview questionsTop trending selenium interview questions
Top trending selenium interview questionsRock Interview
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answerskavinilavuG
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: DemystifiedSeth McLaughlin
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium WorkshopClever Moe
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
 
Integrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala ProjectIntegrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala ProjectKnoldus Inc.
 

La actualidad más candente (20)

Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup Edinburgh
 
Testing with Codeception
Testing with CodeceptionTesting with Codeception
Testing with Codeception
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
 
CI / CD w/ Codeception
CI / CD w/ CodeceptionCI / CD w/ Codeception
CI / CD w/ Codeception
 
Testing PHP with Codeception
Testing PHP with CodeceptionTesting PHP with Codeception
Testing PHP with Codeception
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 
Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)Testing with Codeception (Webelement #30)
Testing with Codeception (Webelement #30)
 
Selenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And AnswersSelenium Automation Testing Interview Questions And Answers
Selenium Automation Testing Interview Questions And Answers
 
Integration Testing in Python
Integration Testing in PythonIntegration Testing in Python
Integration Testing in Python
 
Automation Frame works Instruction Sheet
Automation Frame works Instruction SheetAutomation Frame works Instruction Sheet
Automation Frame works Instruction Sheet
 
Top trending selenium interview questions
Top trending selenium interview questionsTop trending selenium interview questions
Top trending selenium interview questions
 
Selenium Handbook
Selenium HandbookSelenium Handbook
Selenium Handbook
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
Front-End Testing: Demystified
Front-End Testing: DemystifiedFront-End Testing: Demystified
Front-End Testing: Demystified
 
Advanced Selenium Workshop
Advanced Selenium WorkshopAdvanced Selenium Workshop
Advanced Selenium Workshop
 
Selenium web driver
Selenium web driverSelenium web driver
Selenium web driver
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Integrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala ProjectIntegrating Selenium testing infrastructure into Scala Project
Integrating Selenium testing infrastructure into Scala Project
 

Similar a Codeception

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
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using RubyKumari Warsha Goel
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Test Automation Using Selenium
Test Automation Using SeleniumTest Automation Using Selenium
Test Automation Using SeleniumNikhil Kapoor
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With SeleniumMarakana Inc.
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With SeleniumJodie Miners
 
Using galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingUsing galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingSarah Elson
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
If you have not yet done so, you should complete the Module 5 lab .docx
If you have not yet done so, you should complete the Module 5 lab .docxIf you have not yet done so, you should complete the Module 5 lab .docx
If you have not yet done so, you should complete the Module 5 lab .docxwilcockiris
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day OneTroy Miles
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScriptSimon Guest
 

Similar a Codeception (20)

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!
 
Sel
SelSel
Sel
 
Selenium
SeleniumSelenium
Selenium
 
Qa process
Qa processQa process
Qa process
 
Qa process
Qa processQa process
Qa process
 
Selenium Automation Using Ruby
Selenium Automation Using RubySelenium Automation Using Ruby
Selenium Automation Using Ruby
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Test Automation Using Selenium
Test Automation Using SeleniumTest Automation Using Selenium
Test Automation Using Selenium
 
Testing Java Web Apps With Selenium
Testing Java Web Apps With SeleniumTesting Java Web Apps With Selenium
Testing Java Web Apps With Selenium
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Using galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testingUsing galen framework for automated cross browser layout testing
Using galen framework for automated cross browser layout testing
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
Selenium
SeleniumSelenium
Selenium
 
If you have not yet done so, you should complete the Module 5 lab .docx
If you have not yet done so, you should complete the Module 5 lab .docxIf you have not yet done so, you should complete the Module 5 lab .docx
If you have not yet done so, you should complete the Module 5 lab .docx
 
Selenium
SeleniumSelenium
Selenium
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
Automated Testing using JavaScript
Automated Testing using JavaScriptAutomated Testing using JavaScript
Automated Testing using JavaScript
 

Último

Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?SANGHEE SHIN
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfAnna Loughnan Colquhoun
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum ComputingGDSC PJATK
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceMartin Humpolec
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 

Último (20)

Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?Do we need a new standard for visualizing the invisible?
Do we need a new standard for visualizing the invisible?
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Spring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdfSpring24-Release Overview - Wellingtion User Group-1.pdf
Spring24-Release Overview - Wellingtion User Group-1.pdf
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Introduction to Quantum Computing
Introduction to Quantum ComputingIntroduction to Quantum Computing
Introduction to Quantum Computing
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
Things you didn't know you can use in your Salesforce
Things you didn't know you can use in your SalesforceThings you didn't know you can use in your Salesforce
Things you didn't know you can use in your Salesforce
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 

Codeception

  • 2. ACCEPTANCE TESTING Selenium WebDriver, PhpBrowser. Data cleanup. Continuous Integration. Remote Code Coverage. Symfony2, Laravel, Yii, Phalcon, Zend Framework, Kohana, Databases, REST, SOAP, CodeCoverage FUNCTIONAL TESTING API TESTING REST, SOAP, XML-RPC via PHPBrowser or PHP Frameworks. BDD-style PHP Testing BDD的重點是通過與利益相關者的討論取 得對預期的軟體行為的清晰認識。它通過 用自然語言書寫非程式設計師可讀的測試 用例擴展了測試驅動開發方法。 開發者得以把精力集中在代碼應該怎 麼寫,而不是技術細節上,而且也最大程 度的減少了將代碼編寫者的技術語言與商 業客戶、用戶、利益相關者、專案管理者 等的領域語言之間來回翻譯的代價。
  • 3. ACCEPTANCE TESTING This scenario can be performed either by a simple PHP browser or by a browser with Selenium WebDriver. Acceptance testing can be performed by a non-technical person. You can reproduce a AcceptanceTester‘s actions in scenarios and run them automatically after each site change. Generated scenarios will be stored in your _data directory in text files.
  • 4. PHP BROWSER This is the fastest way to run acceptance tests, since it doesn't require running an actual browser. We use a PHP web scrapper, which acts like a browser: it sends a request, then receives and parses the response. Before we start we need a local copy of the site running on your host. We need to specify the url parameter in the acceptance suite config (tests/acceptance.suite.yml). Get Start
  • 5. start by creating a 'Cept' file in the tests/acceptance directory. Let's call it SigninCept.php The wantTo section describes your scenario in brief. The $I object is used to write all interactions. The methods of the $I object are taken from thePHPBrowser and Db modules.If you have ever written a BDD scenario in Gherkin, you can write a classic feature story:
  • 6. CLICK Emulates a click on valid anchors As a parameter you can specify the link name or a valid CSS or XPath selector. You can specify locator type manually by passing array as a parameter. We call this a strict locator. Available strict locator types are: • id • name • css • xpath • link • class
  • 7. SEELINK Before clicking the link you can perform a check if the link really exists on a page. This can be done by the seeLink action
  • 8. FORMS Let's submit this sample form inside the Codeception test. Rewitten scenarioTesting scenario
  • 9. AJAX EMULATION PHP browser can't process JavaScript. Still, all the ajax calls can be easily emulated by sending the proper requests to the server.
  • 10. ASSERTIONS Test the page contents The most useful command for this is see. check that specific element exists (or not) other useful commands to perform checks. Please note that they all start with the see prefix.
  • 11. CONDITIONAL ASSERTIONS Sometimes you don't want the test to be stopped when an assertion fails Maybe you have a long-running test and you want it to run to the end REPLACEMENT : see => canSee dontSee => cantSee
  • 12. GRABBERS These commands retrieves data that can be used in test. Imagine, your site generates a password for every user and you want to check the user can log into the site using this password. Grabbers allow you to get a single value from the current page with commands.
  • 13. COMMENTS Commands like amGoingTo, expect , expectTo helps you in making tests
  • 15. SELENIUM WEBDRIVER Most scenarios can be easily ported between the testing backends Your PhpBrowser tests we wrote previously can be executed inside a real browser (or even PhantomJS) with Selenium WebDriver. Change reconfigure and rebuild the AcceptanceTester class, to use WebDriver instead of PhpBrowser.
  • 16. SELENIUM WEBDRIVER In order to run Selenium tests you need to download Selenium Server and get it running (Alternatively you may use PhantomJS headless browser in ghostdriver mode). If you run acceptance tests with Selenium, Firefox will be started and all actions will be performed step by step using browser engine.
  • 17. In this case seeElement won't just check that the element exists on a page, but it will also check that element is actually visible to user.
  • 18. WAIT While testing web application, you may need to wait for JavaScript events to occur. Due to its asynchronous nature, complex JavaScript interactions are hard to test.
  • 19. MULTI SESSION TESTING Codeception allows you to execute actions in concurrent session. The most obvious case for it - testing realtime messaging between users on site. In order to do it you will need to launch 2 browser windows in a same time for the same test. Codeception has very smart concept for doing this. It is called Friends.
  • 20. CLEANING THINGS UP While testing, your actions may change the data on the site. Tests will fail if trying to create or update the same data twice. To avoid this problem, your database should be repopulated for each test. To make repopulation work, create an sql dump of your database and put it into the /tests/_data directory
  • 21. DEBUGGING Codeception modules can print valuable information while running. Just execute tests with the --debug option to see running details. For any custom output use codecept_debug function. On each fail, the snapshot of the last shown page will be stored in the tests/_log directory. PHPBrowser will store html code and WebDriver will save the screenshot of a page.
  • 22. ACCEPTANCE TESTING Selenium WebDriver, PhpBrowser. Data cleanup. Continuous Integration. Remote CodeCoverage. Symfony2, Laravel, Yii, Phalcon, Zend Framework, Kohana, Databases, REST, SOAP, CodeCoverage FUNCTIONAL TESTING API TESTING REST, SOAP, XML-RPC via PHPBrowser or PHP Frameworks.
  • 23. FUNCTIONAL TESTS Functional tests don't require a web server to run tests. In simple terms we set $_REQUEST, $_GET and$_POST variables then we execute application from a test. Modules for all of these frameworks share the same interface, and thus your tests are not bound to any one of them. This is a sample functional test. As you see you can use same tests for functional and acceptance testing.
  • 24. PITFALLS less stable Headers, Cookies, Sessions One of the common issues problems with functional tests are usage of PHP functions that deal with headers, sessions, cookies. For instance, Header function triggers an error if it is executed more then once. In functional tests, we run application multiple times thus, we will get lots of trash errors in the result. Shared Memory PHP application does not stop after it finished processing a request As all requests run in one memory container they are not isolated. So if you see that your tests are mysteriously failing when they shouldn't – try to execute a single test.
  • 25. ENABLING FRAMEWORK MODULES Symfony2 Just need to include the Symfony2 module into your test suite. If you also use Doctrine2, don't forget to include it either. By default this module will search for App Kernel in the app directory. The module uses the Symfony Profiler to provide additional information and assertions.
  • 26. LARAVEL 4 YII YII2 Yii2 tests are included in Basic and Advanced application templates. Follow Yii2 guides to start. By itself Yii framework does not have an engine for functional testing. So Codeception is the first and only functional testing framework for Yii. To use it with Yii include Yii1 module into config.
  • 27. Zend Framework 2 Zend Framework 1.x The module for Zend Framework is highly inspired by ControllerTestCase class, used for functional testing with PHPUnit. It follows similar approaches for bootstrapping and cleaning up. To start using Zend Framework in your functional tests, include the ZF1 module.
  • 28. Phalcon 1.x Phalcon1 module requires creating bootstrap file which returns instance of PhalconMvcApplication. To start functional tests with Phalcon you should enable Phalon1 module and provid path to this bootstrap file:
  • 29. WRITING FUNCTIONAL TESTS Functional tests are written in the same manner as Acceptance Tests with PhpBrowser module enabled. Click submit form
  • 30. Aassertion Framework modules Access framework globals inside a test or access Depenency Injection containers inside FunctionalHelper class.
  • 31. ERROR REPORTING Uses E_ALL & ~E_STRICT & ~E_DEPRECATED error reporting value In functional tests you might want to change this values depending on framework's error policy. error_level can be set globally in codeception.yml file.
  • 32. ACCEPTANCE TESTING Selenium WebDriver, PhpBrowser. Data cleanup. Continuous Integration. Remote CodeCoverage. Symfony2, Laravel, Yii, Phalcon, Zend Framework, Kohana, Databases, REST, SOAP, CodeCoverage FUNCTIONAL TESTING API TESTING REST, SOAP, XML-RPC via PHPBrowser or PHP Frameworks.
  • 33. UNIT TESTS Codeception uses PHPUnit as a backend for running tests. Thus, any PHPUnit test can be added to Codeception test suite and then executed. If you ever wrote a PHPUnit test then do it just as you did before. Codeception adds some nice helpers to simplify common tasks. To say it again: you don't need to install PHPUnit to run its tests. Codeception can run them too.
  • 34. CREATING TEST Nice generators to simplify test creation. start with generating a classical PHPUnit test extending PHPUnit_Framework_TestCase class Need another command to create Codeception-powered unit test Both tests will create a new ExampleTest file located in tests/unit directory. A test created by generate:test command will look like this:
  • 35. Has predefined _before and _after methods to start with. Use them to create a tested object before each test, and destroy it afterwards.
  • 36. BDD SPECIFICATION TESTING For this case we have a stand-alone project Specify(included in phar package) for writing specifications inside a unit test.
  • 37. USING MODULES As in scenario-driven functional or acceptance tests you can access actor class methods. If you write integration tests, it may be useful to include Db module for database testing. To access UnitTester methods you can use UnitTester property in a test.
  • 38. TESTING DATABASE Database will be cleaned and populated after each test, as it happens for acceptance and functional tests. If it's not your required behavior, please change the settings of Db module for current suite.
  • 39. ACCESSING MODULE Codeception allows you to access properties and methods of all modules defined for this suite. Unlike using the UnitTester class for this purpose, using module directly grants you access to all public properties of that module. All public variables are listed in references for corresponding modules.
  • 40. CEST Alternatively to testcases extended from PHPUnit_Framework_TestCase you may use Codeception-specific Cest format. It does not require to be extended from any other class. All public methods of this class is a test. The example above can be rewritten in scenario-driven manner like this:
  • 41. For unit testing you may include Asserts module, that adds regular assertions to UnitTester which we access from $t variable.
  • 42. STUBS Codeception provides a tiny wrapper over PHPUnit mocking framework to create stubs easily. Include CodeceptionUtilStub to start creating dummy objects. In this example we instantiate object without calling a constructor and replace getName method to return jon value. Stubs are created with PHPUnit's mocking framework. Alternatively you can use Mockery (with Mockery module), AspectMock or others.