SlideShare a Scribd company logo
© 2018 Magento, Inc. Page | 1
Automated Testing in
Magento 2
Igor Miniailo
Magento 2 Architect
© 2018 Magento, Inc. Page | 2
© 2018 Magento, Inc. Page | 3
© 2018 Magento, Inc. Page | 4
*Automated Testing in Magento 2
based on examples from Multi-Source
Inventory
© 2018 Magento, Inc. Page | 5
MSI is designed to enable stock management in multiple
locations so that merchants can properly reflect their physical
warehouses in Magento system without external extensions or
customization
Multi-Source Inventory (MSI)
https://github.com/magento-engcom/msi/
© 2018 Magento, Inc. Page | 6
Split the inventory
between the
sources within one
Magento installation
© 2018 Magento, Inc. Page | 7
Replace current CatalogInventory with MSI
© 2018 Magento, Inc. Page | 8
© 2018 Magento, Inc. Page | 9
© 2018 Magento, Inc. Page | 10
Unit Testing
© 2018 Magento, Inc. Page | 11
Unit test types
https://martinfowler.com/bliki/UnitTest.html
© 2018 Magento, Inc. Page | 12
Test Doubles
https://martinfowler.com/bliki/TestDouble.html
© 2018 Magento, Inc. Page | 13
© 2018 Magento, Inc. Page | 14
Let’s see how typical Unit test for this code looks like
© 2018 Magento, Inc. Page | 15
Solitary Unit Test with Mocks and Expects
© 2018 Magento, Inc. Page | 16
TTDD - Tautological Test Driven Development
Tautological: - needless, redundant repetition of an idea - repetition of
same sense in different words; - the phrase "a beginner who has just
started" is tautological
© 2018 Magento, Inc. Page | 17
TTDD - Tautological Test Driven Development
Unit tests currently do not check that code works
properly, but check that code works the same way
as we implemented it.
Coupling between Production and Testing code.
Test duplicates the business logic code.
© 2018 Magento, Inc. Page | 18
http://fabiopereira.me/blog/2010/05/27/ttdd-tautological-
test-driven-development-anti-pattern/
© 2018 Magento, Inc. Page | 19
• Asserts more interactions with collaborators than the outputs
• It doesn’t really test the behavior of the class, but only its
implementation
• The test is too white box
• Too much mock setup deviates the intent of the test
• Adding a new feature or changing an existing one requires
changing mock expectations
• Such tests don’t help to find bugs in application code
© 2018 Magento, Inc. Page | 20
The problem is not in Unit tests
The problem is in Transient State of objects
under the test
(especially in legacy code)
© 2018 Magento, Inc. Page | 21
© 2018 Magento, Inc. Page | 22
Two Unit tests passed. No Integration tests
© 2018 Magento, Inc. Page | 23
Two Unit tests passed. No Integration tests
© 2018 Magento, Inc. Page | 24
Whether Unit tests are useless?
NO!
Unit tests could be the first “Smell” informing that
something wrong with your application code
© 2018 Magento, Inc. Page | 25
• Readability
– Test should be easy to follow
– Test should be simple to update
– Code can be reused to test all similar cases
• Stability
– Test should be stable by execution
– Test should be stable to code changes
– Test should focus on result not on the path
• Speed
Qualities of a Test
© 2018 Magento, Inc. Page | 26
Integration Testing
© 2018 Magento, Inc. Page | 27
Reservation - the entity is used when the order is placed and
we need to reserve some product quantity in stock.
Reservations are append only operations and help us to prevent
blocking operations and race conditions at the time of checkout.
Reservation mechanism
https://github.com/magento-engcom/msi/wiki/Reservations
© 2018 Magento, Inc. Page | 28
Order Placement – Step 1
France Warehouse
SKU-1: 5qty
EU Stock
SKU-1: 15qty
Italy Warehouse
SKU-1: 10qty
Raw data Index Reservations
No records
Available Qty: 15qty (data from index, empty reservations)
© 2018 Magento, Inc. Page | 29
Order Placement – Step 2
Action: Customer buys 5 products on frontend
© 2018 Magento, Inc. Page | 30
Order Placement – Step 3
France Warehouse
SKU-1: 5qty
EU Stock
SKU-1: 15qty
Italy Warehouse
SKU-1: 10qty
Raw data Index Reservations
SKU-1: -5
Available Qty: 10qty (data from index 15, apply all reservations -5)
Data is NOT changed Reservation has been
added
© 2018 Magento, Inc. Page | 31
Order Placement – Step 4
Action: Admin makes a re-order, 3 products out of 5 returned,
and new order consists of 2 products
© 2018 Magento, Inc. Page | 32
Order Placement – Step 5
France Warehouse
SKU-1: 5qty
EU Stock
SKU-1: 15qty
Italy Warehouse
SKU-1: 10qty
Raw data Index Reservations
SKU-1: -5
SKU-1: +3
Available Qty: 13qty (data from index 15, apply reservations -5+3)
Data is NOT changed
Reservation has been added
© 2018 Magento, Inc. Page | 33
Order Placement – Step 6
Action: Admin completes order. Re-index was run.
© 2018 Magento, Inc. Page | 34
Order Placement – Step 7
France Warehouse
SKU-1: 3qty
EU Stock
SKU-1: 13qty
Italy Warehouse
SKU-1: 10qty
Raw data Index Reservations
SKU-1: -5
SKU-1: +3
SKU-1: +2
Available Qty: 13qty (data from index 13, apply reservations -5+3+2=0)
Data is CHANGED Compensation Reservation
has been added
© 2018 Magento, Inc. Page | 35
Order Placement – Step 8
Action: Reservation cleaning
Looping through these reservations we could find reservations
which in sum gives 0 (Zero) and remove them.
© 2018 Magento, Inc. Page | 36
Order Placement – Step 9 (like Step 1)
France Warehouse
SKU-1: 3qty
EU Stock
SKU-1: 13qty
Italy Warehouse
SKU-1: 10qty
Raw data Index Reservations
Available Qty: 13qty (data from index, empty reservations)
Data is NOT changed Reservations have been removed
No records
© 2018 Magento, Inc. Page | 37
API interface to test
© 2018 Magento, Inc. Page | 38
So, what’s about testing?
© 2018 Magento, Inc. Page | 39
What about fixtures?
© 2018 Magento, Inc. Page | 40
© 2018 Magento, Inc. Page | 41
Tests Isolation
© 2018 Magento, Inc. Page | 42
Using DocBlock Annotations
http://devdocs.magento.com/guides/v2.2/test/integration/annotations.html
© 2018 Magento, Inc. Page | 43
© 2018 Magento, Inc. Page | 44
Clean the state after your tests!
© 2018 Magento, Inc. Page | 45
Cleaning up the state. Rollback Fixtures
© 2018 Magento, Inc. Page | 46
Cleaning up the state. Rollback Fixtures
© 2018 Magento, Inc. Page | 47
Cleaning up the state
© 2018 Magento, Inc. Page | 48
• Readability
– Test should be easy to follow
– Test should be simple to update
– Code can be reused to test all similar cases
• Stability
– Test should be stable by execution
– Test should be stable to code changes
– Test should focus on result not on the path
• Speed
Qualities of a Test
© 2018 Magento, Inc. Page | 49
Web API Testing
© 2018 Magento, Inc. Page | 50
© 2018 Magento, Inc. Page | 51
© 2018 Magento, Inc. Page | 52
© 2018 Magento, Inc. Page | 53
Headless Magento
© 2018 Magento, Inc. Page | 54
RESTful API
© 2018 Magento, Inc. Page | 55
Swagger
http://devdocs.magento.com/guides/v2.2/rest/generate-local.html
© 2018 Magento, Inc. Page | 56
Web API tests
https://github.com/magento-engcom/msi/wiki/How-to-create-Web-API-and-How-To-cover-them-with-Functional-Testing
© 2018 Magento, Inc. Page | 57
Database Generated IDs
© 2018 Magento, Inc. Page | 58
Why can’t we just use predefined IDs?
© 2018 Magento, Inc. Page | 59
Predefined ID approach (used in MSI)
© 2018 Magento, Inc. Page | 60
Predefined IDs matter
Just for this particular case (Source to Stock assignment) - we got rid of more
than 300 lines of boilerplate code in our Integration tests using Pre-Generated
IDs approach.
https://github.com/magento-engcom/msi/wiki/The-first-step-towards-pre-generated-
IDs.-And-how-this-will-improve-your-Integration-tests
© 2018 Magento, Inc. Page | 61
Be Responsible or train your dog tests to be!
© 2018 Magento, Inc. Page | 62
Static Testing
© 2018 Magento, Inc. Page | 63
Strict Typing
© 2018 Magento, Inc. Page | 64
declare(strict_types=1)
© 2018 Magento, Inc. Page | 65
© 2018 Magento, Inc. Page | 66
LiveCodeTest
© 2018 Magento, Inc. Page | 67
Functional Testing
© 2018 Magento, Inc. Page | 68
http://devdocs.magento.com/guides/v2.2/mtf/mtf_introduction.html
© 2017 Magento, Inc. Page | 69
How to join us? Send an email to
engcom@magento.com
@iminyaylo
Thank y’all!

More Related Content

Similar to Automated Testing in Magento 2

Magento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and OverviewMagento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and Overview
Tom Erskine
 
A long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NLA long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NL
Igor Miniailo
 
Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
 Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup) Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
ShilpaGajbhiye2
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
Meet Magento Italy
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
Igor Miniailo
 
API design best practices
API design best practicesAPI design best practices
API design best practices
Igor Miniailo
 
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
 
Magento best practices
Magento best practicesMagento best practices
Magento best practices
Alessandro Ronchi
 
Magento Technical guidelines
Magento Technical guidelinesMagento Technical guidelines
Magento Technical guidelines
Elogic Magento Development
 
Magento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data PatchesMagento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data Patches
atishgoswami
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020
Slava Mankivski
 
Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
Igor Miniailo
 
Magento 2.1 ee content staging
Magento 2.1 ee content stagingMagento 2.1 ee content staging
Magento 2.1 ee content staging
Anton Kaplya
 
Mli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensionsMli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensions
Hanoi MagentoMeetup
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
LocNguyen362
 
BigCommerce Akeneo Connector
BigCommerce Akeneo ConnectorBigCommerce Akeneo Connector
BigCommerce Akeneo Connector
Webkul Software Pvt. Ltd.
 
Level Of Automation Powerpoint Presentation Slides
Level Of Automation Powerpoint Presentation SlidesLevel Of Automation Powerpoint Presentation Slides
Level Of Automation Powerpoint Presentation Slides
SlideTeam
 
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZBackward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
Igor Miniailo
 
James Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With YouJames Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With You
Meet Magento Italy
 

Similar to Automated Testing in Magento 2 (20)

Magento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and OverviewMagento Function Testing Framework - Intro and Overview
Magento Function Testing Framework - Intro and Overview
 
A long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NLA long way from Monolith to Service Isolated Architecture #MM19NL
A long way from Monolith to Service Isolated Architecture #MM19NL
 
Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
 Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup) Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
Demystifying Multi Source Inventory(MSI) - M2NGP03 (Virtual Meetup)
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
 
Backwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NLBackwards Compatibility Developers Guide. #MM17NL
Backwards Compatibility Developers Guide. #MM17NL
 
API design best practices
API design best practicesAPI design best practices
API design best practices
 
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
 
Magento best practices
Magento best practicesMagento best practices
Magento best practices
 
Magento Technical guidelines
Magento Technical guidelinesMagento Technical guidelines
Magento Technical guidelines
 
Magento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data PatchesMagento 2.3 Schema and Data Patches
Magento 2.3 Schema and Data Patches
 
Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020Magento Commerce Global contribution day 2020
Magento Commerce Global contribution day 2020
 
Backward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide WebinarBackward Compatibility Developer's Guide Webinar
Backward Compatibility Developer's Guide Webinar
 
Magento 2.1 ee content staging
Magento 2.1 ee content stagingMagento 2.1 ee content staging
Magento 2.1 ee content staging
 
Mli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensionsMli 2017 technical first steps to building secure Magento extensions
Mli 2017 technical first steps to building secure Magento extensions
 
Vue Vuex 101
Vue Vuex 101Vue Vuex 101
Vue Vuex 101
 
BigCommerce Akeneo Connector
BigCommerce Akeneo ConnectorBigCommerce Akeneo Connector
BigCommerce Akeneo Connector
 
Level Of Automation Powerpoint Presentation Slides
Level Of Automation Powerpoint Presentation SlidesLevel Of Automation Powerpoint Presentation Slides
Level Of Automation Powerpoint Presentation Slides
 
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZBackward Compatibility Developer's Guide in Magento 2. #MM17CZ
Backward Compatibility Developer's Guide in Magento 2. #MM17CZ
 
James Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With YouJames Zetlen - PWA Studio Integration…With You
James Zetlen - PWA Studio Integration…With You
 

More from Magecom UK Limited

Magento Meetup #12. Alex Shkurko.pptx
Magento Meetup #12. Alex Shkurko.pptxMagento Meetup #12. Alex Shkurko.pptx
Magento Meetup #12. Alex Shkurko.pptx
Magecom UK Limited
 
Magento Meetup #12 Anastasiia Bondar
Magento Meetup #12 Anastasiia BondarMagento Meetup #12 Anastasiia Bondar
Magento Meetup #12 Anastasiia Bondar
Magecom UK Limited
 
Magento Meetup #12 Vlad Opukhlyi
Magento Meetup #12 Vlad OpukhlyiMagento Meetup #12 Vlad Opukhlyi
Magento Meetup #12 Vlad Opukhlyi
Magecom UK Limited
 
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
Magecom UK Limited
 
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magecom UK Limited
 
Magento enhanced media gallery - Alexander Shkurko
Magento enhanced media gallery - Alexander ShkurkoMagento enhanced media gallery - Alexander Shkurko
Magento enhanced media gallery - Alexander Shkurko
Magecom UK Limited
 
7 ошибок одного Black Friday - Влад Опухлый
7 ошибок одного Black Friday - Влад Опухлый7 ошибок одного Black Friday - Влад Опухлый
7 ошибок одного Black Friday - Влад Опухлый
Magecom UK Limited
 
Magento & Cloud - Korostelov Avexey
Magento & Cloud - Korostelov AvexeyMagento & Cloud - Korostelov Avexey
Magento & Cloud - Korostelov Avexey
Magecom UK Limited
 
Making the Magento 2 Javascript Loading Great Again - Robin van Raan
Making the Magento 2 Javascript Loading Great Again - Robin van RaanMaking the Magento 2 Javascript Loading Great Again - Robin van Raan
Making the Magento 2 Javascript Loading Great Again - Robin van Raan
Magecom UK Limited
 
Deep Dive in Magento DI
Deep Dive in Magento DIDeep Dive in Magento DI
Deep Dive in Magento DI
Magecom UK Limited
 
From Repositories to Commands - Alexander Shkurko
From Repositories to Commands - Alexander Shkurko From Repositories to Commands - Alexander Shkurko
From Repositories to Commands - Alexander Shkurko
Magecom UK Limited
 
Advanced GIT or How to Change the History
Advanced GIT  or How to Change the HistoryAdvanced GIT  or How to Change the History
Advanced GIT or How to Change the History
Magecom UK Limited
 
MSI In-Store Pickup Функционал & сложности
MSI In-Store Pickup Функционал & сложностиMSI In-Store Pickup Функционал & сложности
MSI In-Store Pickup Функционал & сложности
Magecom UK Limited
 
Adobe Stock Integration community project
Adobe Stock Integration community projectAdobe Stock Integration community project
Adobe Stock Integration community project
Magecom UK Limited
 
Proof of Concept for Magento 2 Projects: Occamo’s Razor
Proof of Concept for Magento 2 Projects: Occamo’s RazorProof of Concept for Magento 2 Projects: Occamo’s Razor
Proof of Concept for Magento 2 Projects: Occamo’s Razor
Magecom UK Limited
 
Что нужно знать девелоперу о SEO на этапе проектирования сайта
Что нужно знать девелоперу о SEO на этапе проектирования сайтаЧто нужно знать девелоперу о SEO на этапе проектирования сайта
Что нужно знать девелоперу о SEO на этапе проектирования сайта
Magecom UK Limited
 
Magento-сертификация: инструкция по применению и как это было
Magento-сертификация: инструкция по применению и как это былоMagento-сертификация: инструкция по применению и как это было
Magento-сертификация: инструкция по применению и как это было
Magecom UK Limited
 
Experience in Magento Community Projects
Experience in Magento Community ProjectsExperience in Magento Community Projects
Experience in Magento Community Projects
Magecom UK Limited
 
UI components: synergy of backend and frontend
UI components: synergy of backend and frontendUI components: synergy of backend and frontend
UI components: synergy of backend and frontend
Magecom UK Limited
 
MSI - Reservation Challenges with 3rd-party Systems
MSI - Reservation Challenges with 3rd-party SystemsMSI - Reservation Challenges with 3rd-party Systems
MSI - Reservation Challenges with 3rd-party Systems
Magecom UK Limited
 

More from Magecom UK Limited (20)

Magento Meetup #12. Alex Shkurko.pptx
Magento Meetup #12. Alex Shkurko.pptxMagento Meetup #12. Alex Shkurko.pptx
Magento Meetup #12. Alex Shkurko.pptx
 
Magento Meetup #12 Anastasiia Bondar
Magento Meetup #12 Anastasiia BondarMagento Meetup #12 Anastasiia Bondar
Magento Meetup #12 Anastasiia Bondar
 
Magento Meetup #12 Vlad Opukhlyi
Magento Meetup #12 Vlad OpukhlyiMagento Meetup #12 Vlad Opukhlyi
Magento Meetup #12 Vlad Opukhlyi
 
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
Google Page Insights and Magento 2 — Sergey Nezbritskiy | Magento Meetup Onli...
 
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
Magento NodeJS Microservices — Yegor Shytikov | Magento Meetup Online #11
 
Magento enhanced media gallery - Alexander Shkurko
Magento enhanced media gallery - Alexander ShkurkoMagento enhanced media gallery - Alexander Shkurko
Magento enhanced media gallery - Alexander Shkurko
 
7 ошибок одного Black Friday - Влад Опухлый
7 ошибок одного Black Friday - Влад Опухлый7 ошибок одного Black Friday - Влад Опухлый
7 ошибок одного Black Friday - Влад Опухлый
 
Magento & Cloud - Korostelov Avexey
Magento & Cloud - Korostelov AvexeyMagento & Cloud - Korostelov Avexey
Magento & Cloud - Korostelov Avexey
 
Making the Magento 2 Javascript Loading Great Again - Robin van Raan
Making the Magento 2 Javascript Loading Great Again - Robin van RaanMaking the Magento 2 Javascript Loading Great Again - Robin van Raan
Making the Magento 2 Javascript Loading Great Again - Robin van Raan
 
Deep Dive in Magento DI
Deep Dive in Magento DIDeep Dive in Magento DI
Deep Dive in Magento DI
 
From Repositories to Commands - Alexander Shkurko
From Repositories to Commands - Alexander Shkurko From Repositories to Commands - Alexander Shkurko
From Repositories to Commands - Alexander Shkurko
 
Advanced GIT or How to Change the History
Advanced GIT  or How to Change the HistoryAdvanced GIT  or How to Change the History
Advanced GIT or How to Change the History
 
MSI In-Store Pickup Функционал & сложности
MSI In-Store Pickup Функционал & сложностиMSI In-Store Pickup Функционал & сложности
MSI In-Store Pickup Функционал & сложности
 
Adobe Stock Integration community project
Adobe Stock Integration community projectAdobe Stock Integration community project
Adobe Stock Integration community project
 
Proof of Concept for Magento 2 Projects: Occamo’s Razor
Proof of Concept for Magento 2 Projects: Occamo’s RazorProof of Concept for Magento 2 Projects: Occamo’s Razor
Proof of Concept for Magento 2 Projects: Occamo’s Razor
 
Что нужно знать девелоперу о SEO на этапе проектирования сайта
Что нужно знать девелоперу о SEO на этапе проектирования сайтаЧто нужно знать девелоперу о SEO на этапе проектирования сайта
Что нужно знать девелоперу о SEO на этапе проектирования сайта
 
Magento-сертификация: инструкция по применению и как это было
Magento-сертификация: инструкция по применению и как это былоMagento-сертификация: инструкция по применению и как это было
Magento-сертификация: инструкция по применению и как это было
 
Experience in Magento Community Projects
Experience in Magento Community ProjectsExperience in Magento Community Projects
Experience in Magento Community Projects
 
UI components: synergy of backend and frontend
UI components: synergy of backend and frontendUI components: synergy of backend and frontend
UI components: synergy of backend and frontend
 
MSI - Reservation Challenges with 3rd-party Systems
MSI - Reservation Challenges with 3rd-party SystemsMSI - Reservation Challenges with 3rd-party Systems
MSI - Reservation Challenges with 3rd-party Systems
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 

Automated Testing in Magento 2

  • 1. © 2018 Magento, Inc. Page | 1 Automated Testing in Magento 2 Igor Miniailo Magento 2 Architect
  • 2. © 2018 Magento, Inc. Page | 2
  • 3. © 2018 Magento, Inc. Page | 3
  • 4. © 2018 Magento, Inc. Page | 4 *Automated Testing in Magento 2 based on examples from Multi-Source Inventory
  • 5. © 2018 Magento, Inc. Page | 5 MSI is designed to enable stock management in multiple locations so that merchants can properly reflect their physical warehouses in Magento system without external extensions or customization Multi-Source Inventory (MSI) https://github.com/magento-engcom/msi/
  • 6. © 2018 Magento, Inc. Page | 6 Split the inventory between the sources within one Magento installation
  • 7. © 2018 Magento, Inc. Page | 7 Replace current CatalogInventory with MSI
  • 8. © 2018 Magento, Inc. Page | 8
  • 9. © 2018 Magento, Inc. Page | 9
  • 10. © 2018 Magento, Inc. Page | 10 Unit Testing
  • 11. © 2018 Magento, Inc. Page | 11 Unit test types https://martinfowler.com/bliki/UnitTest.html
  • 12. © 2018 Magento, Inc. Page | 12 Test Doubles https://martinfowler.com/bliki/TestDouble.html
  • 13. © 2018 Magento, Inc. Page | 13
  • 14. © 2018 Magento, Inc. Page | 14 Let’s see how typical Unit test for this code looks like
  • 15. © 2018 Magento, Inc. Page | 15 Solitary Unit Test with Mocks and Expects
  • 16. © 2018 Magento, Inc. Page | 16 TTDD - Tautological Test Driven Development Tautological: - needless, redundant repetition of an idea - repetition of same sense in different words; - the phrase "a beginner who has just started" is tautological
  • 17. © 2018 Magento, Inc. Page | 17 TTDD - Tautological Test Driven Development Unit tests currently do not check that code works properly, but check that code works the same way as we implemented it. Coupling between Production and Testing code. Test duplicates the business logic code.
  • 18. © 2018 Magento, Inc. Page | 18 http://fabiopereira.me/blog/2010/05/27/ttdd-tautological- test-driven-development-anti-pattern/
  • 19. © 2018 Magento, Inc. Page | 19 • Asserts more interactions with collaborators than the outputs • It doesn’t really test the behavior of the class, but only its implementation • The test is too white box • Too much mock setup deviates the intent of the test • Adding a new feature or changing an existing one requires changing mock expectations • Such tests don’t help to find bugs in application code
  • 20. © 2018 Magento, Inc. Page | 20 The problem is not in Unit tests The problem is in Transient State of objects under the test (especially in legacy code)
  • 21. © 2018 Magento, Inc. Page | 21
  • 22. © 2018 Magento, Inc. Page | 22 Two Unit tests passed. No Integration tests
  • 23. © 2018 Magento, Inc. Page | 23 Two Unit tests passed. No Integration tests
  • 24. © 2018 Magento, Inc. Page | 24 Whether Unit tests are useless? NO! Unit tests could be the first “Smell” informing that something wrong with your application code
  • 25. © 2018 Magento, Inc. Page | 25 • Readability – Test should be easy to follow – Test should be simple to update – Code can be reused to test all similar cases • Stability – Test should be stable by execution – Test should be stable to code changes – Test should focus on result not on the path • Speed Qualities of a Test
  • 26. © 2018 Magento, Inc. Page | 26 Integration Testing
  • 27. © 2018 Magento, Inc. Page | 27 Reservation - the entity is used when the order is placed and we need to reserve some product quantity in stock. Reservations are append only operations and help us to prevent blocking operations and race conditions at the time of checkout. Reservation mechanism https://github.com/magento-engcom/msi/wiki/Reservations
  • 28. © 2018 Magento, Inc. Page | 28 Order Placement – Step 1 France Warehouse SKU-1: 5qty EU Stock SKU-1: 15qty Italy Warehouse SKU-1: 10qty Raw data Index Reservations No records Available Qty: 15qty (data from index, empty reservations)
  • 29. © 2018 Magento, Inc. Page | 29 Order Placement – Step 2 Action: Customer buys 5 products on frontend
  • 30. © 2018 Magento, Inc. Page | 30 Order Placement – Step 3 France Warehouse SKU-1: 5qty EU Stock SKU-1: 15qty Italy Warehouse SKU-1: 10qty Raw data Index Reservations SKU-1: -5 Available Qty: 10qty (data from index 15, apply all reservations -5) Data is NOT changed Reservation has been added
  • 31. © 2018 Magento, Inc. Page | 31 Order Placement – Step 4 Action: Admin makes a re-order, 3 products out of 5 returned, and new order consists of 2 products
  • 32. © 2018 Magento, Inc. Page | 32 Order Placement – Step 5 France Warehouse SKU-1: 5qty EU Stock SKU-1: 15qty Italy Warehouse SKU-1: 10qty Raw data Index Reservations SKU-1: -5 SKU-1: +3 Available Qty: 13qty (data from index 15, apply reservations -5+3) Data is NOT changed Reservation has been added
  • 33. © 2018 Magento, Inc. Page | 33 Order Placement – Step 6 Action: Admin completes order. Re-index was run.
  • 34. © 2018 Magento, Inc. Page | 34 Order Placement – Step 7 France Warehouse SKU-1: 3qty EU Stock SKU-1: 13qty Italy Warehouse SKU-1: 10qty Raw data Index Reservations SKU-1: -5 SKU-1: +3 SKU-1: +2 Available Qty: 13qty (data from index 13, apply reservations -5+3+2=0) Data is CHANGED Compensation Reservation has been added
  • 35. © 2018 Magento, Inc. Page | 35 Order Placement – Step 8 Action: Reservation cleaning Looping through these reservations we could find reservations which in sum gives 0 (Zero) and remove them.
  • 36. © 2018 Magento, Inc. Page | 36 Order Placement – Step 9 (like Step 1) France Warehouse SKU-1: 3qty EU Stock SKU-1: 13qty Italy Warehouse SKU-1: 10qty Raw data Index Reservations Available Qty: 13qty (data from index, empty reservations) Data is NOT changed Reservations have been removed No records
  • 37. © 2018 Magento, Inc. Page | 37 API interface to test
  • 38. © 2018 Magento, Inc. Page | 38 So, what’s about testing?
  • 39. © 2018 Magento, Inc. Page | 39 What about fixtures?
  • 40. © 2018 Magento, Inc. Page | 40
  • 41. © 2018 Magento, Inc. Page | 41 Tests Isolation
  • 42. © 2018 Magento, Inc. Page | 42 Using DocBlock Annotations http://devdocs.magento.com/guides/v2.2/test/integration/annotations.html
  • 43. © 2018 Magento, Inc. Page | 43
  • 44. © 2018 Magento, Inc. Page | 44 Clean the state after your tests!
  • 45. © 2018 Magento, Inc. Page | 45 Cleaning up the state. Rollback Fixtures
  • 46. © 2018 Magento, Inc. Page | 46 Cleaning up the state. Rollback Fixtures
  • 47. © 2018 Magento, Inc. Page | 47 Cleaning up the state
  • 48. © 2018 Magento, Inc. Page | 48 • Readability – Test should be easy to follow – Test should be simple to update – Code can be reused to test all similar cases • Stability – Test should be stable by execution – Test should be stable to code changes – Test should focus on result not on the path • Speed Qualities of a Test
  • 49. © 2018 Magento, Inc. Page | 49 Web API Testing
  • 50. © 2018 Magento, Inc. Page | 50
  • 51. © 2018 Magento, Inc. Page | 51
  • 52. © 2018 Magento, Inc. Page | 52
  • 53. © 2018 Magento, Inc. Page | 53 Headless Magento
  • 54. © 2018 Magento, Inc. Page | 54 RESTful API
  • 55. © 2018 Magento, Inc. Page | 55 Swagger http://devdocs.magento.com/guides/v2.2/rest/generate-local.html
  • 56. © 2018 Magento, Inc. Page | 56 Web API tests https://github.com/magento-engcom/msi/wiki/How-to-create-Web-API-and-How-To-cover-them-with-Functional-Testing
  • 57. © 2018 Magento, Inc. Page | 57 Database Generated IDs
  • 58. © 2018 Magento, Inc. Page | 58 Why can’t we just use predefined IDs?
  • 59. © 2018 Magento, Inc. Page | 59 Predefined ID approach (used in MSI)
  • 60. © 2018 Magento, Inc. Page | 60 Predefined IDs matter Just for this particular case (Source to Stock assignment) - we got rid of more than 300 lines of boilerplate code in our Integration tests using Pre-Generated IDs approach. https://github.com/magento-engcom/msi/wiki/The-first-step-towards-pre-generated- IDs.-And-how-this-will-improve-your-Integration-tests
  • 61. © 2018 Magento, Inc. Page | 61 Be Responsible or train your dog tests to be!
  • 62. © 2018 Magento, Inc. Page | 62 Static Testing
  • 63. © 2018 Magento, Inc. Page | 63 Strict Typing
  • 64. © 2018 Magento, Inc. Page | 64 declare(strict_types=1)
  • 65. © 2018 Magento, Inc. Page | 65
  • 66. © 2018 Magento, Inc. Page | 66 LiveCodeTest
  • 67. © 2018 Magento, Inc. Page | 67 Functional Testing
  • 68. © 2018 Magento, Inc. Page | 68 http://devdocs.magento.com/guides/v2.2/mtf/mtf_introduction.html
  • 69. © 2017 Magento, Inc. Page | 69 How to join us? Send an email to engcom@magento.com @iminyaylo Thank y’all!