Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Vitalyi Golomoziy - Integration tests in Magento 2

731 views

Published on

In the talk we has discussed how integration tests are structured in Magento 2, main elements of integration tests framework, will see an example of an integration test.
We has talked about an impact of integration tests to a project quality and timeline.
We has also compared integration and unit tests, discussed pros and cons of each type of testing.

  • Login to see the comments

Vitalyi Golomoziy - Integration tests in Magento 2

  1. 1. ABOUT MYSELF • Architect and SME for Magento U • Working in Magento for more than 8 years
  2. 2. TABLE OF CONTENTS • Automated testing in Magento 2 • Integration tests framework overview • Writing a simple integration test
  3. 3. AUTOMATED TESTING IN MAGENTO 2
  4. 4. QUALITY OFTHE AUTOMATEDTEST FragilityAccuracy Savings Costs
  5. 5. AUTOMATEDTESTING IN MAGENTO 2 • Unit testing • Integration testing • Functional testing
  6. 6. UNIT TEST • TDD • Better code structure • Execution of every line of the code Fragility Accuracy
  7. 7. FUNCTIONAL TEST • Business scenarios testing • Ensuring the whole system is working as expected • Edge case in user’s behavior testing Accuracy Fragility
  8. 8. INTEGRATION TEST • Code-level feature testing • Testing feature connected to the infrastructure Accuracy Fragility
  9. 9. INTEGRATION TESTS FRAMEWORK OVERVIEW
  10. 10. FRAMEWORK • Based on phpunit • Provides magento-specific annotations • Provides a lot of magento-specific tools • Special object manager object
  11. 11. CONFIGURATION • etc/install-config-mysql.php • etc/config-global.php • etc/di/preferences/(ce.php|ee.php) • phpunit.xml
  12. 12. USEFUL ANNOTATIONS • @magentoDataFixture • @magentoAppIsolation • @magentoDbIsolation • @magentoAppArea • @magentoCache • @magentoConfigFixture
  13. 13. MAGENTO TEST CASES • AbstractController • AbstractBackendController • AbstractConfigFile • AbstractIntegrity
  14. 14. ADD SHARED INSTANCE PHPUnit_Framework_MockObject_MockObject $transportBuilderMock, $originalClassName ) { $userMock = $this->_objectManager->create( $originalClassName, ['transportBuilder' => $transportBuilderMock] ); $factoryMock = $this->getMockBuilder('MagentoUserModelUserFactory') ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); $factoryMock->method('create') ->willReturn($userMock); $this->_objectManager->addSharedInstance( $factoryMock, 'MagentoUserModelUserFactory' ); }
  15. 15. WRITING A SIMPLE INTEGRATION TEST
  16. 16. CONFIGURATION return [ 'db-host' => 'localhost', 'db-user' => ’__database_user__', 'db-password' => ’__password__', 'db-name' => ’special_db_for_integration_tests', 'db-prefix' => '', 'backend-frontname' => 'admin', 'admin-user' => MagentoTestFrameworkBootstrap::ADMIN_NAME, 'admin-password' => MagentoTestFrameworkBootstrap::ADMIN_PASSWORD, 'admin-email' => MagentoTestFrameworkBootstrap::ADMIN_EMAIL, 'admin-firstname' => MagentoTestFrameworkBootstrap::ADMIN_FIRSTNAME, 'admin-lastname' => MagentoTestFrameworkBootstrap::ADMIN_LASTNAME, ];
  17. 17. FIXTURES <?php global $students; $students = [ [’name' => ’John’, ‘surname’ => ‘Doe’], [’name' => ’Another John’, ‘surname’ => ‘Doe’], ];
  18. 18. TEST /** * @magentoDataFixture __path_to_fixture_file.php * @magentoDbIsolation enabled * @magentoAppIsolation enabled * @magentoAppArea adminhtml */ public function testCRUD() { global $students; $model = $this->studentsFactory>create(); $model->setName($students[0][’name’]) ->setSurname($students[0][‘surname’]); $crud = new MagentoTestFrameworkEntity($model); $crud->testCrud(); }
  19. 19. Q&A
  20. 20. THANKYOU FOR ATTENTION

×