What do you use for Unit Testing in Magento? Or what do you know about Unit Testing and Magento? Whether you do TDD or you just want to have unit test coverage for your project components, you need some tools to do this.

The first basic approach is to use plain phpunit, but there are things that need additional gimmicks to make Magento "testable".

Everything I worked with is related to phpunit:

Are there other options?

4 Answers 4


Check out PHPSpec with MageSpec if you want something not based on PHPUnit, but with some Magento Integration. Its usable, but not just quite ready for prime time. For mocking PHPSpec 2 uses Prophecy (which is great), but doesn't like magic getters and setters at all. For that reason its better to use Mockery instead, which works fine (and I also like it a lot).

Then there also is Behat with BehatMage for BDD with Magento. Worth a look, but it fails in for example if you want to test different store views on different domains.

There also is an extension to BehatMage called MageBehat (awful naming!), which came out of a hackathon. It provides a lot of Magento specific actions to BehatMage, but to be honest, some of the workarounds used are more of a hack then real solutions to the underlying issues. Still, its usable.

I hope to see both projects - MageSpec and BehatMage - flourish in future.

  • Thank you Vinai for your reply. I know about BehatMage and the work done by the team at Inviqa/Session Digital (it's unclear to me their company structure)... I was looking only for phpunit stuff, Behat/BehatMage it's not that appealing to me, I did play with MageSpec a while ago. Commented Nov 23, 2013 at 20:22
  • English is not my native language, the details I provided could have been clearer. I am doing some research for London Magento User Group - December Meetup. Commented Nov 24, 2013 at 23:26

PHPUnit is what Magento 2 uses. Here is a sample file on GitHub. https://github.com/magento/magento2/blob/master/dev/tests/unit/testsuite/Magento/Captcha/Helper/DataTest.php. (I picked that file at random.) You might want to have a quick look at the Magento 2 test approach so that anything you do now is compatible with Magento 2 when released.

  • I don't think the OP is talking about Magneto 2 here.
    – Marius
    Commented Nov 27, 2013 at 8:28

You should go with EcomDev PHPUnit.

I personally believe that all Magento developers should strive for a consistent unit testing solution. EcomDev provide the most commonly used and most mature of these frameworks so you already have a decent pool of developers with experience in it. Using a single framework also reduces the need to install a bajillion different frameworks.

EcomDev PHPUnit does have this odd convention of putting tests directly alongside the production code, however. Fortunately, this is easily addressed by modifying a few lines of code. EcomDev also take their sweet time with updates (although their Github repo shows signs of activity so they're clearly still alive).

  • So, saying all that, is there a repo somewhere that has a set of defined unit tests (using ecomdev_unittest) that tests core functionality? (I know MTAF does this, but is there pre-defined unit tests somewhere?)
    – ProxiBlue
    Commented Nov 24, 2013 at 1:01
  • 1
    @ProxiBlue No, there aren't any that I am aware of. That's a pretty good idea for a community project, however.
    – Thai Phan
    Commented Nov 24, 2013 at 2:11

For unit testing EcomDev PHPUnit is the best.

Maybe you want to try fonctionnal testing on Magento? Example with casperjs : https://github.com/jacquesbh/hackathon-casperjs/

  • 1
    there was a different question about this. Commented Nov 26, 2013 at 13: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.