Magento – Tools for Unit Testing in Magento

ecomdev-phpunittestingunit tests

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?

Best Answer

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.