1
  • 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 ?

1 Answer 1

2
  • 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!

2
  • Personally I've struggled to do Magento 2 Dev using TDD (test driven development) because things have to be done in very particular ways to get it working in the M2 environment (making a custom ui component for example) HOWEVER, once I have my code working, I've found it to be useful to write tests to check things with complex logic or multiple different outcomes (the data provider of the ui component listing). Another benefit, is that when we decide to have another feature, I can make my new changes, and check whether the old Unit tests are still green. That's been surprisingly helpful! Oct 23, 2020 at 2:44
  • 1
    exactly right, I am not using tests on daily basis, and that is my own mistake. But when I do, I feel backed up and more confident in writing code that will have quality assurance beyond what's is written at the time of coding Oct 23, 2020 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.