SlideShare a Scribd company logo
Magento 2
integration tests
What is Magento?
One of the most popular Ecommerce platforms
All the stuff that one web shop needs
Used on 1.3% of all websites (http://w3techs.com/technologies/overview/content_management/all)
Based on PHP, MySQL….
Free and paid versions
Modular approach (Catalog, Category, Checkout, Sales…)
Magento grew over years
Huge number of extensions
Huge number of features
Huge community
Magento 2
Announced 2010
Refactor / rewrite
Goals:
Modern tech stack
Improved performance and scalability
Streamline customizations
Simplify external integrations
Easier installation and upgrades
High code quality and testing
More info: http://alankent.me/2014/05/17/magento-2-goals/
Magento 2 introduces
Namespaces
Composer
Jquery instead of Prototype
Dependency injection
Service contracts
Plugins
XML Schema validation
Automated tests
Automated testing vs manual testing
Executed more quickly
Reusable
Everyone can see results
Costs less
More reliable
More interesting
More info: http://www.base36.com/2013/03/automated-vs-manual-testing-the-pros-and-cons-of-each/
Automated tests in Magento 2
Unit tests
Integration tests
Functional tests
Other tests (performance, legacy...):
More info: http://alankent.me/2014/06/28/magento-2-test-automation/
Integration tests
“Integration tests show that the major parts of a system work
well together”
- The Pragmatic Programmer Book
The official Magento automated testing standard
Integration tests:
Deployed on close to real environment.
Integration tests verify interaction of components between each other and with system
environment (database, file system).
The goals are to tackle cross-dependencies between components/modules and environment-
related issues.
Integration test can also be considered as a "small" functional test, so its goal to preserve
functionality
More info: https://github.com/magento/magento2/wiki/Magento-Automated-Testing-Standard
Difference from unit tests
Unit tests test the smallest units of code, integration tests test how those units
work together
Integration tests touch more code
Integration tests have less mocking and less isolation
Unit tests are faster
Unit tests are easier to debug
Difference from functional tests
Functional tests compare against the specification
Functional tests are slower
Functional tests can tell us if something visible to the customer broke
Integration tests in Magento 2
Based on PHPUnit
Can touch the database and filesystem
Have separate database
Separated into modules
Magento core code is tested with integration tests
Make updates easier
From my experience most of the common mistakes would be picked up by
integration tests
Setup
bin/magento dev:test:run integration
cd dev/tests/integration && phpunit -c phpunit.xml
Separate database: dev/tests/integration/etc/install-config-mysql.php.dist
Configuration in dev/tests/integration/phpunit.xml.dist
TESTS_CLEANUP
TESTS_MAGENTO_MODE
TESTS_ERROR_LOG_LISTENER_LEVEL
Annotations
/**
* Test something
*
* @magentoConfigFixture currency/options/allow USD
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
public function testSomething()
{
}
Annotations
/**
* Test something
*
* @magentoConfigFixture currency/options/allow USD
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
public function testSomething()
{
}
What are annotations
Meta data used to inject some behaviour
Placed in docblocks
Change test behaviour
PHPUnit_Framework_TestListener
onTestStart, onTestSuccess, onTestFailure, etc
More info: http://dusanlukic.com/annotations-in-magento-2-integration-tests
@magentoDbIsolation
when enabled wraps the test in a transaction
enabled - makes sure that the tests don’t affect each other
disabled - useful for debugging as data remains in database
can be applied on class level and on method level
@magentoConfigFixture
Sets the config value
/**
* @magentoConfigFixture current_store sales_email/order/attachagreement 1
*/
@magentoDataFixture
/dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price.php
$product = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->create('MagentoCatalogModelProduct');
$product->setTypeId('simple')
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Simple Product')
->setSku('simple')
->setPrice(10)
->setMetaTitle('meta title')
->setMetaKeyword('meta keyword')
->setMetaDescription('meta description')
->setVisibility(MagentoCatalogModelProductVisibility::VISIBILITY_BOTH)
->setStatus(MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED)
->setStockData(['use_config_manage_stock' => 0])
->setSpecialPrice('5.99')
->save();
Rollback script
/dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price_rollback.php
$product = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->create('MagentoCatalogModelProduct');
$product->load(1);
if ($product->getId()) {
$product->delete();
}
Some examples
Integration tests can do much more
Don’t test Magento framework, test your own code
Test that that non existing category goes to 404
class CategoryTest extends
MagentoTestFrameworkTestCaseAbstractController
{
/*...*/
public function testViewActionInactiveCategory()
{
$this->dispatch('catalog/category/view/id/8');
$this->assert404NotFound();
}
/*...*/
}
Save and load entity
$obj = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->get('LDusanSampleModelExampleFactory')
->create();
$obj->setVar('value');
$obj->save();
$id = $something->getId();
$repo = MagentoTestFrameworkHelperBootstrap::getObjectManager()
->get('LDusanSampleApiExampleRepositoryInterface');
$example = $repo->getById($id);
$this->assertSame($example->getVar(), 'value');
Real life example, Fooman_EmailAttachments
Most of the stores have terms and agreement
An email is sent to the customer after each successful order
Goal: Provide the option of attaching terms and agreement to order
success email
Send an email and check contents
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php
* @magentoConfigFixture current_store sales_email/order/attachagreement 1
*/
public function testWithHtmlTermsAttachment()
{
$orderSender = $this->objectManager->create('MagentoSalesModelOrderEmailSenderOrderSender');
$orderSender->send($order);
$termsAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'text/html; charset=UTF-8');
$this->assertContains('Checkout agreement content', base64_decode($termsAttachment['Body']));
}
public function getLastEmail()
{
$this->mailhogClient->setUri(self::BASE_URL . 'v2/messages?limit=1');
$lastEmail = json_decode($this->mailhogClient->request()->getBody(), true);
$lastEmailId = $lastEmail['items'][0]['ID'];
$this->mailhogClient->resetParameters(true);
$this->mailhogClient->setUri(self::BASE_URL . 'v1/messages/' . $lastEmailId);
return json_decode($this->mailhogClient->request()->getBody(), true);
}
The View
Layout
Block
Template
Goal: Insert a block into catalog product view page
Block
/app/code/LDusan/Sample/Block/Sample.php
<?php
namespace LDusanSampleBlock;
class Sample extends MagentoFrameworkViewElementTemplate
{
}
Layout
/app/code/LDusan/Sample/view/frontend/layout/catalog_product_view.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"
>
<body>
<referenceContainer name="content">
<block class="LDusanSampleBlockSample" name="ldusan-sample-block"
template="LDusan_Sample::sample.phtml" />
</referenceContainer>
</body>
</page>
Template
/app/code/LDusan/Sample/view/frontend/templates/sample.phtml
<p>This should appear in catalog product view page!</p>
Test if block is added correctly
<?php
namespace LDusanSampleController;
class ActionTest extends MagentoTestFrameworkTestCaseAbstractController
{
/**
* @magentoDataFixture Magento/Catalog/_files/product_special_price.php
*/
public function testBlockAdded()
{
$this->dispatch('catalog/product/view/id/' . $product->getId());
$layout = MagentoTestFrameworkHelperBootstrap::getObjectManager()->get(
'MagentoFrameworkViewLayoutInterface'
);
$this->assertArrayHasKey('ldusan-sample-block', $layout->getAllBlocks());
}
}
To summarize
Integration tests are not:
The only tests that you should write
Integration tests are:
A way to check if something really works as expected
Proof that our code works well with the environment
Thanks!
Slides on Twitter: @LDusan
Questions?

More Related Content

What's hot

DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
Dakiry
 
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
Engineor
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
Mikhail Subach
 
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFTRFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
Yogindernath Gupta
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
Engineor
 
Keyword Driven Automation
Keyword Driven AutomationKeyword Driven Automation
Keyword Driven Automation
Pankaj Goel
 
UFT Automation Framework Introduction
UFT Automation Framework IntroductionUFT Automation Framework Introduction
UFT Automation Framework IntroductionHimal Bandara
 
Automation Framework/QTP Framework
Automation Framework/QTP FrameworkAutomation Framework/QTP Framework
Automation Framework/QTP Framework
HeyDay Software Solutions
 
Automation framework
Automation framework Automation framework
Automation framework ITeLearn
 
Test Tooling in Visual Studio 2012 an overview
Test Tooling in Visual Studio 2012 an overviewTest Tooling in Visual Studio 2012 an overview
Test Tooling in Visual Studio 2012 an overview
Clemens Reijnen
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven TestingMaveryx
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightDevnology
 
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
Yogindernath Gupta
 
Coded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object ModelCoded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object Model
Tharinda Liyanage
 
Codeception
CodeceptionCodeception
Codeception
Jonathan Lau
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
IlPeach
 

What's hot (18)

DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
DaKiRY_BAQ2016_QADay_Marta Firlej "Microsoft Test Manager tool – how can we u...
 
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
 
Keyword-driven Test Automation Framework
Keyword-driven Test Automation FrameworkKeyword-driven Test Automation Framework
Keyword-driven Test Automation Framework
 
Rft courseware
Rft coursewareRft courseware
Rft courseware
 
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFTRFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
RFT Tutorial 4 How Do We Record A Script Using Rational Functional Tester - RFT
 
TESTLINK INTEGRATOR
TESTLINK INTEGRATORTESTLINK INTEGRATOR
TESTLINK INTEGRATOR
 
Codeception: introduction to php testing
Codeception: introduction to php testingCodeception: introduction to php testing
Codeception: introduction to php testing
 
Keyword Driven Automation
Keyword Driven AutomationKeyword Driven Automation
Keyword Driven Automation
 
UFT Automation Framework Introduction
UFT Automation Framework IntroductionUFT Automation Framework Introduction
UFT Automation Framework Introduction
 
Automation Framework/QTP Framework
Automation Framework/QTP FrameworkAutomation Framework/QTP Framework
Automation Framework/QTP Framework
 
Automation framework
Automation framework Automation framework
Automation framework
 
Test Tooling in Visual Studio 2012 an overview
Test Tooling in Visual Studio 2012 an overviewTest Tooling in Visual Studio 2012 an overview
Test Tooling in Visual Studio 2012 an overview
 
Keyword Driven Testing
Keyword Driven TestingKeyword Driven Testing
Keyword Driven Testing
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in Silverlight
 
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
RFT Tutorial - 9 How To Create A Properties Verification Point In Rft For Tes...
 
Coded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object ModelCoded UI: Hand Coding based on Page Object Model
Coded UI: Hand Coding based on Page Object Model
 
Codeception
CodeceptionCodeception
Codeception
 
Codeception introduction and use in Yii
Codeception introduction and use in YiiCodeception introduction and use in Yii
Codeception introduction and use in Yii
 

Viewers also liked

Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)
vinaikopp
 
Dissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedDissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedFranklin Allaire
 
How to Turn Content Into Revenue
How to Turn Content Into RevenueHow to Turn Content Into Revenue
How to Turn Content Into Revenue
Yael Kochman
 
Final 9 7-13
Final 9 7-13Final 9 7-13
Final 9 7-13
SHIVA CSG PVT LTD
 
Human face-of-accessibility
Human face-of-accessibilityHuman face-of-accessibility
Human face-of-accessibility
elianna james
 
940000_Gas Daily_Storage Regulations
940000_Gas Daily_Storage Regulations940000_Gas Daily_Storage Regulations
940000_Gas Daily_Storage RegulationsPaul Bieniawski
 
Wcag 2.0 level_a_all_ejames
Wcag 2.0 level_a_all_ejamesWcag 2.0 level_a_all_ejames
Wcag 2.0 level_a_all_ejames
elianna james
 
Cic rds product portfolio october 2013
Cic rds product portfolio   october 2013Cic rds product portfolio   october 2013
Cic rds product portfolio october 2013
Ehab Fawzy
 
Imp drishti farm to fork club
Imp drishti farm to fork clubImp drishti farm to fork club
Imp drishti farm to fork club
SHIVA CSG PVT LTD
 
Content marketing tips & tricks
Content marketing tips & tricksContent marketing tips & tricks
Content marketing tips & tricksYael Kochman
 
Dbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farmingDbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farming
SHIVA CSG PVT LTD
 
Client case study - GHS
Client case study   - GHSClient case study   - GHS
Client case study - GHS
Paul Tilstone, GTP
 
Service profile scsg mining
Service profile scsg miningService profile scsg mining
Service profile scsg mining
SHIVA CSG PVT LTD
 
Case study of Fem HRS college demonstration @ 22nd feb 2010
Case study of Fem HRS college demonstration @ 22nd feb 2010Case study of Fem HRS college demonstration @ 22nd feb 2010
Case study of Fem HRS college demonstration @ 22nd feb 2010
Archan Gurtu
 
Openployer company info
Openployer company infoOpenployer company info
Openployer company info
Heike Anna Krüger
 
PostGIS on Rails
PostGIS on RailsPostGIS on Rails
PostGIS on Rails
Matt Nemenman
 
Skills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibilitySkills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibility
elianna james
 
QA Accessibility-testing
QA Accessibility-testingQA Accessibility-testing
QA Accessibility-testing
elianna james
 
Lowendalmasaï social charges optimization
Lowendalmasaï social charges optimizationLowendalmasaï social charges optimization
Lowendalmasaï social charges optimization
Giuseppe Mele
 
Lowendalmasaï - Enterprise Cost Management
Lowendalmasaï - Enterprise Cost ManagementLowendalmasaï - Enterprise Cost Management
Lowendalmasaï - Enterprise Cost ManagementGiuseppe Mele
 

Viewers also liked (20)

Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)Getting your hands dirty testing Magento 2 (at MageTitansIT)
Getting your hands dirty testing Magento 2 (at MageTitansIT)
 
Dissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-RevisedDissertation_FULL-DRAFT-Revised
Dissertation_FULL-DRAFT-Revised
 
How to Turn Content Into Revenue
How to Turn Content Into RevenueHow to Turn Content Into Revenue
How to Turn Content Into Revenue
 
Final 9 7-13
Final 9 7-13Final 9 7-13
Final 9 7-13
 
Human face-of-accessibility
Human face-of-accessibilityHuman face-of-accessibility
Human face-of-accessibility
 
940000_Gas Daily_Storage Regulations
940000_Gas Daily_Storage Regulations940000_Gas Daily_Storage Regulations
940000_Gas Daily_Storage Regulations
 
Wcag 2.0 level_a_all_ejames
Wcag 2.0 level_a_all_ejamesWcag 2.0 level_a_all_ejames
Wcag 2.0 level_a_all_ejames
 
Cic rds product portfolio october 2013
Cic rds product portfolio   october 2013Cic rds product portfolio   october 2013
Cic rds product portfolio october 2013
 
Imp drishti farm to fork club
Imp drishti farm to fork clubImp drishti farm to fork club
Imp drishti farm to fork club
 
Content marketing tips & tricks
Content marketing tips & tricksContent marketing tips & tricks
Content marketing tips & tricks
 
Dbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farmingDbpl bioproducts for sustainable farming
Dbpl bioproducts for sustainable farming
 
Client case study - GHS
Client case study   - GHSClient case study   - GHS
Client case study - GHS
 
Service profile scsg mining
Service profile scsg miningService profile scsg mining
Service profile scsg mining
 
Case study of Fem HRS college demonstration @ 22nd feb 2010
Case study of Fem HRS college demonstration @ 22nd feb 2010Case study of Fem HRS college demonstration @ 22nd feb 2010
Case study of Fem HRS college demonstration @ 22nd feb 2010
 
Openployer company info
Openployer company infoOpenployer company info
Openployer company info
 
PostGIS on Rails
PostGIS on RailsPostGIS on Rails
PostGIS on Rails
 
Skills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibilitySkills needed-for-a-job-in-accessibility
Skills needed-for-a-job-in-accessibility
 
QA Accessibility-testing
QA Accessibility-testingQA Accessibility-testing
QA Accessibility-testing
 
Lowendalmasaï social charges optimization
Lowendalmasaï social charges optimizationLowendalmasaï social charges optimization
Lowendalmasaï social charges optimization
 
Lowendalmasaï - Enterprise Cost Management
Lowendalmasaï - Enterprise Cost ManagementLowendalmasaï - Enterprise Cost Management
Lowendalmasaï - Enterprise Cost Management
 

Similar to Magento 2 integration tests

Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
Bartosz Górski
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
Bartosz Górski
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalMax Pronko
 
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
chrisb206 chrisb206
 
Magento++
Magento++Magento++
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
SpringPeople
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Joke Puts
 
Qa process
Qa processQa process
Qa process
Aila Bogasieru
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
Albert Rosa
 
Qa process
Qa processQa process
Qa process
Aila Bogasieru
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App Engine
IndicThreads
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App Engine
Inphina Technologies
 
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
 
Katalon Studio - GUI Overview
Katalon Studio - GUI OverviewKatalon Studio - GUI Overview
Katalon Studio - GUI Overview
Katalon Studio
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Flutter Agency
 
Introduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce PlatformIntroduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce Platform
Jarne W. Beutnagel
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
Ravi Mehrotra
 
Mangento
MangentoMangento
Mangento
Ravi Mehrotra
 
Magento Integration Tests
Magento Integration TestsMagento Integration Tests
Magento Integration Tests
X.commerce
 

Similar to Magento 2 integration tests (20)

Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Zepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_FinalZepplin_Pronko_Magento_Festival Hall 1_Final
Zepplin_Pronko_Magento_Festival Hall 1_Final
 
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
 
Magento++
Magento++Magento++
Magento++
 
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
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
 
Qa process
Qa processQa process
Qa process
 
Code igniter unittest-part1
Code igniter unittest-part1Code igniter unittest-part1
Code igniter unittest-part1
 
Qa process
Qa processQa process
Qa process
 
Testing Your Application On Google App Engine
Testing Your Application On Google App EngineTesting Your Application On Google App Engine
Testing Your Application On Google App Engine
 
Testing your application on Google App Engine
Testing your application on Google App EngineTesting your application on Google App Engine
Testing your application on Google App Engine
 
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!
 
Katalon Studio - GUI Overview
Katalon Studio - GUI OverviewKatalon Studio - GUI Overview
Katalon Studio - GUI Overview
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Introduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce PlatformIntroduction to the Magento eCommerce Platform
Introduction to the Magento eCommerce Platform
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
Magento Integration Tests
Magento Integration TestsMagento Integration Tests
Magento Integration Tests
 

Recently uploaded

Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 

Recently uploaded (20)

Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 

Magento 2 integration tests

  • 2. What is Magento? One of the most popular Ecommerce platforms All the stuff that one web shop needs Used on 1.3% of all websites (http://w3techs.com/technologies/overview/content_management/all) Based on PHP, MySQL…. Free and paid versions Modular approach (Catalog, Category, Checkout, Sales…)
  • 3. Magento grew over years Huge number of extensions Huge number of features Huge community
  • 4. Magento 2 Announced 2010 Refactor / rewrite Goals: Modern tech stack Improved performance and scalability Streamline customizations Simplify external integrations Easier installation and upgrades High code quality and testing More info: http://alankent.me/2014/05/17/magento-2-goals/
  • 5. Magento 2 introduces Namespaces Composer Jquery instead of Prototype Dependency injection Service contracts Plugins XML Schema validation Automated tests
  • 6. Automated testing vs manual testing Executed more quickly Reusable Everyone can see results Costs less More reliable More interesting More info: http://www.base36.com/2013/03/automated-vs-manual-testing-the-pros-and-cons-of-each/
  • 7. Automated tests in Magento 2 Unit tests Integration tests Functional tests Other tests (performance, legacy...): More info: http://alankent.me/2014/06/28/magento-2-test-automation/
  • 9. “Integration tests show that the major parts of a system work well together” - The Pragmatic Programmer Book
  • 10. The official Magento automated testing standard Integration tests: Deployed on close to real environment. Integration tests verify interaction of components between each other and with system environment (database, file system). The goals are to tackle cross-dependencies between components/modules and environment- related issues. Integration test can also be considered as a "small" functional test, so its goal to preserve functionality More info: https://github.com/magento/magento2/wiki/Magento-Automated-Testing-Standard
  • 11. Difference from unit tests Unit tests test the smallest units of code, integration tests test how those units work together Integration tests touch more code Integration tests have less mocking and less isolation Unit tests are faster Unit tests are easier to debug
  • 12. Difference from functional tests Functional tests compare against the specification Functional tests are slower Functional tests can tell us if something visible to the customer broke
  • 13. Integration tests in Magento 2 Based on PHPUnit Can touch the database and filesystem Have separate database Separated into modules Magento core code is tested with integration tests Make updates easier From my experience most of the common mistakes would be picked up by integration tests
  • 14. Setup bin/magento dev:test:run integration cd dev/tests/integration && phpunit -c phpunit.xml Separate database: dev/tests/integration/etc/install-config-mysql.php.dist Configuration in dev/tests/integration/phpunit.xml.dist TESTS_CLEANUP TESTS_MAGENTO_MODE TESTS_ERROR_LOG_LISTENER_LEVEL
  • 15. Annotations /** * Test something * * @magentoConfigFixture currency/options/allow USD * @magentoAppIsolation enabled * @magentoDbIsolation enabled */ public function testSomething() { }
  • 16. Annotations /** * Test something * * @magentoConfigFixture currency/options/allow USD * @magentoAppIsolation enabled * @magentoDbIsolation enabled */ public function testSomething() { }
  • 17. What are annotations Meta data used to inject some behaviour Placed in docblocks Change test behaviour PHPUnit_Framework_TestListener onTestStart, onTestSuccess, onTestFailure, etc More info: http://dusanlukic.com/annotations-in-magento-2-integration-tests
  • 18. @magentoDbIsolation when enabled wraps the test in a transaction enabled - makes sure that the tests don’t affect each other disabled - useful for debugging as data remains in database can be applied on class level and on method level
  • 19. @magentoConfigFixture Sets the config value /** * @magentoConfigFixture current_store sales_email/order/attachagreement 1 */
  • 20. @magentoDataFixture /dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price.php $product = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->create('MagentoCatalogModelProduct'); $product->setTypeId('simple') ->setAttributeSetId(4) ->setWebsiteIds([1]) ->setName('Simple Product') ->setSku('simple') ->setPrice(10) ->setMetaTitle('meta title') ->setMetaKeyword('meta keyword') ->setMetaDescription('meta description') ->setVisibility(MagentoCatalogModelProductVisibility::VISIBILITY_BOTH) ->setStatus(MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED) ->setStockData(['use_config_manage_stock' => 0]) ->setSpecialPrice('5.99') ->save();
  • 21. Rollback script /dev/tests/integration/testsuite/Magento/Catalog/_files/product_special_price_rollback.php $product = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->create('MagentoCatalogModelProduct'); $product->load(1); if ($product->getId()) { $product->delete(); }
  • 22. Some examples Integration tests can do much more Don’t test Magento framework, test your own code
  • 23. Test that that non existing category goes to 404 class CategoryTest extends MagentoTestFrameworkTestCaseAbstractController { /*...*/ public function testViewActionInactiveCategory() { $this->dispatch('catalog/category/view/id/8'); $this->assert404NotFound(); } /*...*/ }
  • 24. Save and load entity $obj = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->get('LDusanSampleModelExampleFactory') ->create(); $obj->setVar('value'); $obj->save(); $id = $something->getId(); $repo = MagentoTestFrameworkHelperBootstrap::getObjectManager() ->get('LDusanSampleApiExampleRepositoryInterface'); $example = $repo->getById($id); $this->assertSame($example->getVar(), 'value');
  • 25. Real life example, Fooman_EmailAttachments Most of the stores have terms and agreement An email is sent to the customer after each successful order Goal: Provide the option of attaching terms and agreement to order success email
  • 26. Send an email and check contents /** * @magentoDataFixture Magento/Sales/_files/order.php * @magentoDataFixture Magento/CheckoutAgreements/_files/agreement_active_with_html_content.php * @magentoConfigFixture current_store sales_email/order/attachagreement 1 */ public function testWithHtmlTermsAttachment() { $orderSender = $this->objectManager->create('MagentoSalesModelOrderEmailSenderOrderSender'); $orderSender->send($order); $termsAttachment = $this->getAttachmentOfType($this->getLastEmail(), 'text/html; charset=UTF-8'); $this->assertContains('Checkout agreement content', base64_decode($termsAttachment['Body'])); } public function getLastEmail() { $this->mailhogClient->setUri(self::BASE_URL . 'v2/messages?limit=1'); $lastEmail = json_decode($this->mailhogClient->request()->getBody(), true); $lastEmailId = $lastEmail['items'][0]['ID']; $this->mailhogClient->resetParameters(true); $this->mailhogClient->setUri(self::BASE_URL . 'v1/messages/' . $lastEmailId); return json_decode($this->mailhogClient->request()->getBody(), true); }
  • 27. The View Layout Block Template Goal: Insert a block into catalog product view page
  • 31. Test if block is added correctly <?php namespace LDusanSampleController; class ActionTest extends MagentoTestFrameworkTestCaseAbstractController { /** * @magentoDataFixture Magento/Catalog/_files/product_special_price.php */ public function testBlockAdded() { $this->dispatch('catalog/product/view/id/' . $product->getId()); $layout = MagentoTestFrameworkHelperBootstrap::getObjectManager()->get( 'MagentoFrameworkViewLayoutInterface' ); $this->assertArrayHasKey('ldusan-sample-block', $layout->getAllBlocks()); } }
  • 32. To summarize Integration tests are not: The only tests that you should write Integration tests are: A way to check if something really works as expected Proof that our code works well with the environment
  • 33. Thanks! Slides on Twitter: @LDusan Questions?