Path

ez.no / ezpublish / documentation / development / test suite


Test Suite

These documentation pages are no longer maintained. Please visit the new documentation site.

From version 3.4 eZ publish includes a test suite for unit tests inside it's SVN tree (http://pubsvn.ez.no/viewcvs/ezp/trunk/tests/). With this test suite we test if functionality in eZ publish still works when we add a new feature, fix a bug, or before we make a new release.

Running the Test Suite

Running the test suite is easy, just go to the root directory of your eZ publish checkout, and run:

php tests/testunits.php {modulename}

At the moment there is only one module: eztemplate, so a sample invocation would be:

php tests/testunits.php eztemplate

In case you only want to run one test, you can specify that by adding ":{functionname}" to the module name. This function name is case-sensitive. An example:

php tests/testunits.php eztemplate:Function

You can even run one element from a function:

php tests/testunits.php eztemplate:Function:Block

The output of running those tests shows per unit (element of a function in a module) whether it succeeded or not, some similar to:

eZTemplate::ProcessedOperator::Is_type              [Success]

eZTemplate::ProcessedOperator::L10n                [Failure]

 * #1 assert: String compare of processed results

eZTemplate::ProcessedOperator::Logical             [Success]

eZTemplate::ProcessedOperator::Makedate            [Success]

Adding tests to the template 'function'

At the moment most of the tests test template functions and operators. Adding a new test element for those is really easy.

  1. Go to the correct directory (tests/eztemplate/operators for operator tests and tests/eztemplate/functions for function tests)
  2. Create a new file containing a template, and name that file "operator-name" + ".tpl" (or function-name of course), like: "datetime.tpl"
  3. Create a new file containing the expected output and name that file "operator-name" + ".exp"
  4. Optionally create a file with the name "operator-name" + ".php". This file will be included before the template fetch of "operator-name" + ".tpl"

That's all, you can now see if your new test is succesful by running the test suite.

Adding a new function to a test module

Adding a new function needs a little bit more work, but it not really hard either.

Inside the test files (eztemplateoutput.php, eztemplateoperator.php etc) you find the following basic structure:

class {name of test class} extends eZTestCase {

 

   function {name of test class}( $name = false )

   {

       $this->eZTestCase( $name );

       $this->addTest( {testname}, {testdescription} );

       ...

   }

 

   function {testname}( &$tr ) {

       ...

   }

}

In the constructor of the class you need to call "addTest" for every unit test in this class. A unit is always put in a method. Inside this method you're free to implement your test case with what ever means you see fit, but the final action should always be:

$tr->assert( {comparison of actual and expected}, {description if things go wrong} );

A good example of a comparison is something like "strcmp($actual_output, $expected_output) == 0" and an example of a description might be something like "String compare of actual and expected result".

Other assertions that you can use are:

function assert( $assertion, $message = false )

 function assertEquals( $actual, $expected, $message = false )

 function assertNotEquals( $actual, $expected, $message = false )

 function assertSimilar( $actual, $expected, $message = false )

 function assertNotSimilar( $actual, $expected, $message = false )
  • assert() expects a boolean (true or false) as $assertion parameter
  • assertEquals() uses === to compare $actual and $expected
  • assertNotEquals() uses !== to compare $actual and $expected
  • assertSimilar() uses == to compare $actual and $expected
  • assertNotSimilar() uses != to compare $actual and $expected

Adding a new test module

If you are adding a whole new module then you have to edit/create another file in addition to the file above. This is the "testsuite.php" file which you need to have in each directory containing tests (f.e. tests/eztemplate/testsuite.php). The format of this PHP file is as follows:

<?php

$SuiteDefinition = array( 'name' => '{module name}',

                         'tests' => array() );

 

$SuiteDefinition['tests'][] = array(

 'name' => '{function name}',

 'file' => '{filename which contains the tests (see above)}.php',

 'class' => '{the name of the class providing the tests}'

);

?>

f.e.:

$SuiteDefinition['tests'][] = array(

 'name' => 'ProcessedFunction',

 'file' => 'eztestprocessedtemplatefunction.php',

 'class' => 'eZTestProcessedTemplateFunction'

);

The {module name} is the name of the test module that shows up in the reports, and can be used to specify which tests to run, like "eztemplate".

Comments

Running unit test

Test Suite says to run it from the documentation. However it is not very easy. Could you clarify? How is a new extension tested?

Contents

Development

Extensions
eZ publish datamodel
eZ publish tuning and stability
Importing attribute data
Kernel
Libraries
Scripting
Standards
System overview
Test Suite
Using Doxygen to create API documenta...


Created

11/05/2004
1:48:43 pm
by Derick Rethans

Last updated

13/09/2004
5:41:26 am
by glenn bell

Authors

Derick Rethans
glenn bell



This page is part of the eZ Publish documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.