TransWikia.com

How the unit tests in magento 2 are useful?

Magento Asked on February 21, 2021

  • I’d like to know, what are the core benefits of running tests in
    magento ?
  • How & what can be determined from the tests ?
  • How to run a test ?

One Answer

  • Assuming you know Magento well, if you implement your changes directly on your Magento system without tests, you will feel quite productive.

  • when you don't have exposure to tests, it is a learning curve to use them

  • if you don't use tests though, then you are liable to test manually your changes. And more importantly, you have to tests the other parts of the system are not broken. (who can claim has never been surprised to find a small change to break something at the other end of the system and found out 8 months down the line..).

--> that means manual tests are not reliable and are not scalable

Below are some thoughts on how to get to test (one day) your code (not too worry, I am only slightly further than you are..

  1. writing tests is a lot easier with smaller classes, try to keep the amount of dependency injections low help to have less to mock
  2. a good starting point is to learn to write small classes before you even think of writing tests.. otherwise you will tire out quickly and won't ever see the benefit
  3. you might add tests, but if they cover only the obvious scenarios and leave big gaps, then you end up having a false sense of security
  • however, you will have to start somewhere, right? there are courses out there on unit tests that are outside of Magento and do a great job of making you profficient with the concept

    --> meaning point 1 is easy to get out of the way

  • point 2 is more complex because we all work on legacy Magento systems and it is not easy to change our way of writing. But following best practices or learning through online portal like mage2.tv can help as these do use good way of writing code

  • point 3 is quite subtil and only experience will fill this gap, so no need to worry about now.

Good luck!

Correct answer by Herve Tribouilloy on February 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP