How to set up Magento to for running tests and basics on using the Magento 2 integration test framework.
This presentation was given at #MageTestFest in Amersfoort in on November 17th, 2017.
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
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
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
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
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