Magento testing, audit and code analysis methods and tools

- E-Commerce, Magento tips & tricks

In this post, we are going to talk about different Magento tools for testing, audit and code analysis. There are 3 major groups of testing: Unit, Functional and Integration. They all have their goals, so you should know their major features to choose the most suitable for your issue. Of course, there are extensions and services developed to perform testing, audit and code analysis for Magento, but let’s start from the theoretical aspect of the problem.

The first major software testing method is a unit testing. Its main goal is to determine if individual parts of source code and different sets of program modules work correctly. This testing method relies on units as the smallest testable parts of an application. A unit could be an individual function, an entire module or interface. The gradation depends on a programming type. Each test case should be independent from the other cases. Substitutes such as mock objects, method stubs, fakes, and harnesses are usually used in order to assist testing a module in isolation. By performing unit tests, you can get all the necessary information required to understand that code behaves as intended. You set apart each part of the program and find out if individual parts work as expected.

tdd-magento tests

'

Unit test:

  • finds problems in the development cycle;
  • allows code refactoring at a later date;
  • reduces uncertainty in the units;
  • can be used in a bottom-up testing approach;
  • provides a sort of systems living documentation.

Integration testing is a continuation of the previous method. Individual software modules (after they have been tested separately) are combined and tested as a system. By performing integration testing, you can find out if the system is ready for validation testing.

The major types of integration testing are:

Big Bang Testing – major parts of the system or complete software system are tested;

Bottom Up Testing – testing starts from the lowest level components to higher level components;

Top Down Testing – the top integrated modules are tested first and the branch of every module is tested gradually until the end of the related module;

Sandwich Testing combines Top Down of and Bottom Up Testing.

The third software testing method is a functional testing. It is a process of quality assurance based on the specifications of the software component under test. Functional testing consists of two major parts: feeding the input and examining the output. It describes what the system can and rarely considers the internal program structure.

Functional testing consists of:

  • functions identification;
  • input data creation;
  • output determination;
  • test case execution;
  • expected and actual outputs comparison;
  • troubleshooting.

Let’s see how these different types of testing can be performed for Magento.

Magium

Magento testing

Magium is a Selenium based test framework which relies on PHPUnit and Webdriver to streamline browser testing in Magento. The tool provides the ability to bypass much of the boilerplate code which is often required for browser and functional testing. You can find a full description of Magium here: MAGENTO SELENIUM TESTING. Follow the link below to get the tool.

Get Magium

Mage_Test

mage-test

Mage_Test is an integration test framework for Magento driven by community which evolves continuously. The tool is easy to use, and it is compatible with Magento and Mage+. The non-intrusive unit test framework can be integrated into 3rd party extensions. By using this tool, you get a suite of integration tests designed to verify that modifications have not broken any core Magento functionality. You can download Mage_Test from GitHub.

Get Mage_Test from GitHub

The official site

Magento Expert Consulting Group

magento-expert-consukting-group-tests

Magento ECG helps merchants maximize the success of their Magento Enterprise Edition stores. The group of experts provides a comprehensive analysis and offers the best practice recommendations.

PHP_CodeSniffer

You can also use PHP_CodeSniffer, which is a PHP5 script designed to work with PHP, JavaScript and CSS files to detect all the violations of a defined standards. With this tool your code will always remain clean and consistent. In addition, PHP_CodeSniffer can also prevent some troubles caused by common semantic errors made by developers.

Get PHP_CodeSniffer

Magento PHP_CodeSniffer Coding Standard

Magniffer

Magniffer is an extendable and XPath driven static code analysis tool for Magento. The solution is built on the top of PHP-Parser library.

Get Magniffer

PHPUnit

php-unit-magento

PHPUnit is a unit testing framework for the PHP programming language, which uses assertions to verify that the behaviour of a unit under test matches the expected one. It isolates each part of the program and show if individual parts are correct or not. PHPUnit doesn’t change any core files, because a separate database connection is used for every tests and all the system objects are replaced during the run-time.

Get PHPUnit extension for Magento

Tutorial for PHPUnit integration with Magento

Official PHPUnit site

Magento Test Automation Framework

magento-auto-test-framework

Magento TAF is a set of tools used for functional tests against Magento applications. The tools are designed for both actual testing and test automation scripts writing. Last can be used for testing most Magento functions and processes which don’t relate to an external system. Magento Test Automation Framework is a cross-platforming solution. It provides you with the ability to run multiple tests simultaneously or a single test independently.

Get MTAF

The additional information

Magento Automated Testing Guide

BehatMage

Behat is a behavior-driven open source development framework for PHP 5.3/5.4. “Behavior-driven” refers to the process that describes how your application should work by human-readable sentences, and only then implements this behavior into software. The extension allows you to define Magento scenarios to enable BDD within your projects. It is quick to learn and easy use.

Get BehatMage

Behat manual

MageSpec – PHPSpec for Magento

By using this development tool, you can achieve clean and working PHP code. The solution relies on spec behaviour driven development (SpecBDD). MageSpec describes the next object behaviour (specification), writes some code to satisfy that specification and stops to refactor the last increment, allowing the emergent design to show the direction.

Get MageSpec – PHPSpec for Magento

Test Driven Magento Extension Development by Allan MacGregor

Test Driven Magento Extension Development

This is the best book about Magento testing. Based on wide community experience, it helps readers simplify Magento extension development. Unfortunately, testing is used quite rare even among experienced Magento developers, but this book can dramatically change the situation, since it is aimed at lowering an existing entry barrier for building testable and high-quality extensions with the help of TDD principles. Having read Test Driven Magento Extension Development, you can get a deep understanding of a test-first oriented approach, as well as keep your testing skills growing. Check the book here.

'