SlideShare a Scribd company logo
Testing in Magento 2
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
1. Running Tests
2. Writing Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running all the tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ bin/magento dev:tests:run [all | unit | integration]
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running specific tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Unit Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ vendor/bin/phpunit 
--config "dev/tests/unit/phpunit.xml.dist" 
["app/code/My/Module/Test/Unit"]
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ alias unit-test="$(pwd)/vendor/bin/phpunit
-c $(pwd)/dev/tests/unit/phpunit.xml.dist"
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ unit-test
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ unit-test "app/code/My/Module/Test/Unit"
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Test
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
What is the difference?
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Real Objects Interact
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Tests need the
Runtime Environment
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Integration Test Framework Bootstrap:
1. If TESTS_CLEANUP is set
4 clear test environment cache
4 uninstall Magento
2. If Magento is not installed
4 install Magento & dump the DB
4 on consecutive runs:
import the dump before install
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Separate DB
cp dev/tests/integration/etc/install-config-mysql.php.dist 
dev/tests/integration/etc/install-config-mysql.php
vi dev/tests/integration/etc/install-config-mysql.php
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Tweak settings
cp dev/tests/integration/phpunit.xml.dist 
dev/tests/integration/phpunit.xml
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
dev/tests/integration/phpunit.xml.dist
<phpunit>
...
<php>
...
<const name="TESTS_CLEANUP" value="enabled"/>
<!--<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>-->
...
</php>
...
</phpunit>
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
TESTS_CLEANUP == disabled
speeds things up
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
TESTS_CLEANUP == disabled
manual cleanup required
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Enable TESTS_EXTRA_VERBOSE_LOG
in phpunit.xml to see what is going on
during bootstrap.
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Every run gets it's own
etc, pub and var dirs
dev/tests/integration/tmp/sandbox-0-
b79c13eb842cf3211459b11c775bfbde/
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
rm -r integration/tmp/sandbox-*
fresh start!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Executing Integration Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Executing integration tests
!= unit tests
$ vendor/bin/phpunit -c dev/tests/integration/phpunit.xml
Could not read "dev/tests/integration/phpunit.xml".
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
$ cd dev/tests/integration
$ ../../../vendor/bin/phpunit
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Running Tests in
PHPStorm
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
1. Set up PHP interpreter
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
2. Set up PHPUnit (1/2)
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
3. Set up PHPUnit (2/2)
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
4. Create run configuration
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
5. Run tests with one of
^ F10
^ F9 (debug)
or click:
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Tests
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Unit Tests
Nothing Magento 2 specific
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Writing Integration Tests
Very Magento 2 specific
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Magento 2 Testing Framework
dev/tests/integration/framework
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
ObjectManager is a'okay!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Test Framework ObjectManager
MagentoTestFrameworkObjectManager::getInstance()
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Fixtures
Fix the system into a known state
before a test is executed.
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture myCustomFixture
*/
public function testSomethingWithAnOrderAndACustomer()
{
// ...
}
public static function myCustomFixture()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Complex Fixtures:
(e.g. Sessions, Order Placement, Customer...)
https://github.com/tddwizard/magento2-fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Config Fixtures
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Store Scope
/**
* @magentoConfigFixture current_store catalog/price/scope 1
*/
public function testDoesSomeoneReadThisHelpMeLetMeOut()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Global Scope
/**
* @magentoConfigFixture currency/options/allow USD
*/
public function testTastesLikeMashAndPie()
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Test Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
DataBase Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Transactions
/**
* @magentoDbIsolation enabled
*/
public function testWithSideEffects
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Transactions
/**
* @magentoDataFixture Magento/Foo/_files/bar.php
*/
public function testTheFixtureIsAppliedWithinATransaction
{
// ...
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Application Isolation
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Reset Magento after test
/**
* @magentoAppIsolation enabled
*/
public function testTestWithSingletons()
{
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Selecting a application area
/**
* @magentoAppArea frontend
*/
public function testRendersTheCustomerNameInWelcomeMessage()
{
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Most important!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Choose the right test granularity based
on
4 Business Value
4 Personal Skill
4 Available Time
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Don't test for testing's sake
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Make the tests valuable
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
Time for a sip of
☕
before we dive in!
Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp

More Related Content

PDF
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
PDF
Magento 2 TDD Code Kata Intro
PDF
Getting your hands dirty testing Magento 2 (at MageTitansIT)
PDF
Magento 2 TDD Code Kata
PDF
Becoming Certified - MageTitansMCR 2018
PDF
Ajax for PHP Developers
PDF
2020 [pweb] 13 typescript
DOCX
New microsoft word document
Writing Testable Code (for Magento 1 and 2) 2016 Romaina
Magento 2 TDD Code Kata Intro
Getting your hands dirty testing Magento 2 (at MageTitansIT)
Magento 2 TDD Code Kata
Becoming Certified - MageTitansMCR 2018
Ajax for PHP Developers
2020 [pweb] 13 typescript
New microsoft word document

Similar to Testing Magento 2 (20)

PDF
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
PDF
Writing Testable Code (for Magento 1 and 2)
PDF
Writing testable Code (MageTitans Mini 2016)
PDF
The journey of mastering Magento 2 for Magento 1 developers
PDF
Secure development environment @ Meet Magento Croatia 2017
PDF
Automated tests types on Magento 2 example
PDF
ClojureScript in Magento 2 - PHPUGMRN
PPT
Issues and solutions for Magento upgrade(1.8.0.1)
PPTX
Magento 2 development
PPTX
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
PDF
Vinai Kopp - How i develop M2 modules
PPT
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
PDF
Prepara tu entorno para Magento 2
PPTX
Make implementation of third party elements in magento 2 in 5-times easier
PDF
How to Install Magento 2 [Latest Version]
PDF
Contribution Day Guide - MM19JP
PPTX
MidwestPHP - Getting Started with Magento 2
PDF
Faster Magento Integration Tests
PDF
SOS UiComponents
PPTX
Magento2 From Setup To Deployment. Automate Everything
Getting your Hands Dirty Testing Magento 2 (at London Meetup)
Writing Testable Code (for Magento 1 and 2)
Writing testable Code (MageTitans Mini 2016)
The journey of mastering Magento 2 for Magento 1 developers
Secure development environment @ Meet Magento Croatia 2017
Automated tests types on Magento 2 example
ClojureScript in Magento 2 - PHPUGMRN
Issues and solutions for Magento upgrade(1.8.0.1)
Magento 2 development
Dusan Lukic Magento 2 Integration Tests Meet Magento Serbia 2016
Vinai Kopp - How i develop M2 modules
Meet Magento DE 2016 - Kristof Ringleff - Growing up with Magento
Prepara tu entorno para Magento 2
Make implementation of third party elements in magento 2 in 5-times easier
How to Install Magento 2 [Latest Version]
Contribution Day Guide - MM19JP
MidwestPHP - Getting Started with Magento 2
Faster Magento Integration Tests
SOS UiComponents
Magento2 From Setup To Deployment. Automate Everything
Ad

More from vinaikopp (11)

PPTX
Building Mage-OS - MageTitans 2023
PDF
Hyvä: Compatibility Modules
PDF
Hyvä from a developer perspective
PDF
Property Based Testing in PHP
PDF
Property based testing - MageTestFest 2019
PDF
ClojureScript in Magento 2 - MageTitansMCR 2017
PDF
Lizards & Pumpkins Catalog Replacement at mm17de
PDF
Stories from the other side
PDF
Architecture in-the-small-slides
PPT
Modern Module Architecture
PPT
The beautiful Magento module - MageTitans 2014
Building Mage-OS - MageTitans 2023
Hyvä: Compatibility Modules
Hyvä from a developer perspective
Property Based Testing in PHP
Property based testing - MageTestFest 2019
ClojureScript in Magento 2 - MageTitansMCR 2017
Lizards & Pumpkins Catalog Replacement at mm17de
Stories from the other side
Architecture in-the-small-slides
Modern Module Architecture
The beautiful Magento module - MageTitans 2014
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Machine Learning_overview_presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Electronic commerce courselecture one. Pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
MIND Revenue Release Quarter 2 2025 Press Release
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Unlocking AI with Model Context Protocol (MCP)
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Machine Learning_overview_presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

Testing Magento 2

  • 1. Testing in Magento 2 Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 2. 1. Running Tests 2. Writing Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 3. Running all the tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 4. $ bin/magento dev:tests:run [all | unit | integration] Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 5. Running specific tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 6. Unit Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 7. $ vendor/bin/phpunit --config "dev/tests/unit/phpunit.xml.dist" ["app/code/My/Module/Test/Unit"] Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 8. $ alias unit-test="$(pwd)/vendor/bin/phpunit -c $(pwd)/dev/tests/unit/phpunit.xml.dist" Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 9. $ unit-test Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 10. $ unit-test "app/code/My/Module/Test/Unit" Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 11. Integration Test Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 12. What is the difference? Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 13. Real Objects Interact Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 14. Integration Tests need the Runtime Environment Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 15. Integration Test Framework Bootstrap: 1. If TESTS_CLEANUP is set 4 clear test environment cache 4 uninstall Magento 2. If Magento is not installed 4 install Magento & dump the DB 4 on consecutive runs: import the dump before install Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 16. Separate DB cp dev/tests/integration/etc/install-config-mysql.php.dist dev/tests/integration/etc/install-config-mysql.php vi dev/tests/integration/etc/install-config-mysql.php Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 17. Tweak settings cp dev/tests/integration/phpunit.xml.dist dev/tests/integration/phpunit.xml Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 18. dev/tests/integration/phpunit.xml.dist <phpunit> ... <php> ... <const name="TESTS_CLEANUP" value="enabled"/> <!--<const name="TESTS_EXTRA_VERBOSE_LOG" value="1"/>--> ... </php> ... </phpunit> Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 19. TESTS_CLEANUP == disabled speeds things up Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 20. TESTS_CLEANUP == disabled manual cleanup required Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 21. Enable TESTS_EXTRA_VERBOSE_LOG in phpunit.xml to see what is going on during bootstrap. Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 22. Every run gets it's own etc, pub and var dirs dev/tests/integration/tmp/sandbox-0- b79c13eb842cf3211459b11c775bfbde/ Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 23. rm -r integration/tmp/sandbox-* fresh start! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 24. Executing Integration Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 25. Executing integration tests != unit tests $ vendor/bin/phpunit -c dev/tests/integration/phpunit.xml Could not read "dev/tests/integration/phpunit.xml". Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 26. $ cd dev/tests/integration $ ../../../vendor/bin/phpunit Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 27. Running Tests in PHPStorm Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 28. 1. Set up PHP interpreter Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 29. 2. Set up PHPUnit (1/2) Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 30. 3. Set up PHPUnit (2/2) Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 31. 4. Create run configuration Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 32. 5. Run tests with one of ^ F10 ^ F9 (debug) or click: Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 33. Writing Tests Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 34. Writing Unit Tests Nothing Magento 2 specific Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 35. Writing Integration Tests Very Magento 2 specific Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 36. Magento 2 Testing Framework dev/tests/integration/framework Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 37. ObjectManager is a'okay! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 38. Test Framework ObjectManager MagentoTestFrameworkObjectManager::getInstance() Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 39. Fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 40. Fixtures Fix the system into a known state before a test is executed. Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 41. /** * @magentoDataFixture Magento/Sales/_files/order.php * @magentoDataFixture Magento/Customer/_files/customer.php * @magentoDataFixture myCustomFixture */ public function testSomethingWithAnOrderAndACustomer() { // ... } public static function myCustomFixture() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 42. Complex Fixtures: (e.g. Sessions, Order Placement, Customer...) https://github.com/tddwizard/magento2-fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 43. Config Fixtures Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 44. Store Scope /** * @magentoConfigFixture current_store catalog/price/scope 1 */ public function testDoesSomeoneReadThisHelpMeLetMeOut() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 45. Global Scope /** * @magentoConfigFixture currency/options/allow USD */ public function testTastesLikeMashAndPie() { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 46. Test Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 47. DataBase Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 48. Transactions /** * @magentoDbIsolation enabled */ public function testWithSideEffects { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 49. Transactions /** * @magentoDataFixture Magento/Foo/_files/bar.php */ public function testTheFixtureIsAppliedWithinATransaction { // ... Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 50. Application Isolation Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 51. Reset Magento after test /** * @magentoAppIsolation enabled */ public function testTestWithSingletons() { Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 52. Selecting a application area /** * @magentoAppArea frontend */ public function testRendersTheCustomerNameInWelcomeMessage() { Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 53. Most important! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 54. Choose the right test granularity based on 4 Business Value 4 Personal Skill 4 Available Time Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 55. Don't test for testing's sake Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 56. Make the tests valuable Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp
  • 57. Time for a sip of ☕ before we dive in! Testing in Magento 2 - #MageTestFest, Nov. 2017 - contact@vinaikopp.com - twitter://@VinaiKopp