Utilizare i risultatti per altri utili

[experimental] Using the test results for other tools with the Recorder
Careful : this documentation refers to un-released code. It's only available in SVN.

What the developer wants from his tests is immediate feedback. The TextReporter and the HtmlReporter are there to show this feedback. As quickly as possible and as close to your working tools as possible : the console, the browser.

# recorder A Recorder for non-developpers

But often developers don't work alone : you may have a team contributing to the same code base next door, a manager a little bit further away and even a team of testers or power users on the other side of the planet.

For them as well tests' results are valuable pieces of information ! They just need to be formatted and archived somewhere. The Recorder allows you to grab all output to a simple PHP array. <?php require_once('simpletest/autorun.php');<strong> require_once('simpletest/ui/recorder.php');</strong> $group = new TestSuite(); $group->addFile('test_of_module_ship.php'); $group->addFile('test_of_module_pay.php'); <strong> $recorder = new Recorder(); $group->run($recorder);</strong> ?>

Within this $recorder object lies the test suite information. Let's dump the $recorder->results variable and check what's in it : <?php array(4) { [0]=> array(4) { ["time"]=> int(1173951256) ["status"]=> string(6) "Passed" ["test"]=> string(129) "examples/test_of_module_ship.php->TestUsingParcelForce->testParcelForceIsFine" ["message"]=> string(97) " at [examples/test_of_module_ship.php line 7]" } [1]=> array(4) { ["time"]=> int(1173951256) ["status"]=> string(6) "Passed" ["test"]=> string(154) "examples/test_of_module_ship.php->TestUsingMyOwnAirplane->testUsingMyOwnAirplaneOnlyWorksForSmallGifts" ["message"]=> string(134) "Expected false, got [Boolean: false] at [examples/test_of_module_ship.php line 13]" } [2]=> array(4) { ["time"]=> int(1173951256) ["status"]=> string(6) "Passed" ["test"]=> string(135) "examples/test_of_module_pay.php->TestPayForParcelForce->testPayForParcelForceIsFine" ["message"]=> string(96) " at [examples/test_of_module_pay.php line 7]" } [3]=> array(4) { ["time"]=> int(1173951256) ["status"]=> string(6) "Passed" ["test"]=> string(155) "examples/test_of_module_pay.php->TestPayForMyOwnAirplane->testPayForMyOwnAirplaneOnlyWorksForSmallGifts" ["message"]=> string(133) "Expected false, got [Boolean: false] at [examples/test_of_module_pay.php line 13]" } } ?>

# recorder-results Exploring the Recorder results

Each element of the $recoder->results array contains one assertion's information :

- time : when the assertion was executed, in a timestamp format.
- status : either Passed or Failed
- test : the name of the test
- message : the actual message, useful for understanding what went wrong

Now iterating throught the results becomes really easy... <?php require_once('simpletest/autorun.php'); require_once('simpletest/ui/recorder.php'); $group = new TestSuite(); $group->addFile('test_of_module_ship.php'); $group->addFile('test_of_module_pay.php'); $recorder = new Recorder(); $group->run($recorder); <strong>foreach (recorder->results as $result) { if ($result->status == "Failed") { do_something_while_it_is_time(result); } } </strong> ?>

A Recorder for non-developers. Exploring the Recorder results.
The JUnit FAQ has plenty of useful testing advice. Next is grouping test cases together. You will need the SimpleTest testing framework for these examples.
software development, php programming, programming php, software development tools, php tutorial, free php scripts, architecture, php resources, mock objects, junit, php testing, unit test, automated php testing, test cases tutorial, explain unit test case, unit test example, unit test