SHX::PerlUnit - API to perform regression tests on software units. |
use SHX::PerlUnit;
my $pu = new SHX::PerlUnit([$UnitName]); $pu->Load(); $pu->Run(); $pu->Diff(); print $pu->Summary();
Next to creating a PerlUnit object based on an xml file, the test commands are executed and their output are stored in the active session directory. Next, a diff is made beteween the last test session and the current one.
The first argument represents the unit name and also the xml file describing the test unit without the '.xml'. If no unit name provided 'punit' is used.
PerlUnit is an API to perform regression test on any software unit. No changes to the code is needed because the regression tests are performed on executables. In order to describe the tests to be performmed an xml file is used. PerlUnit searches in the working directory a file corresponding to the unit name with a '.xml' appent or to a file named 'punit.xml'. Here is a sample of this file.
<?xml version="1.0" encoding="UTF-8"?> <testunit name="xmlrpc" version="0.9.4"> <!-- the config for this unit --> <config> <!-- set the output path relatively to the current directory and the output format. Available output formats : 'html', 'text' or 'xml' --> <output path="PU" format="html"/> </config> <!-- the tests to made to validate this unit --> <tests> <!-- a test with topic and several commands --> <sample name="test1"> <!-- a description to display during the test execution --> <topic>This a test of the Test :-)</topic> <!-- the list of commands to run to validate this test Validation status is based on the output of the command. --> <cmd>ls</cmd> <cmd>ls --help</cmd> <cmd>ls --version</cmd> </sample> <sample name="test2"> <topic>This an other test</topic> <cmd>test1</cmd> <cmd>test1 --help</cmd> <cmd>test1 --version</cmd> </sample> <sample name="test3"> <topic>This a test of the Test :-)</topic> <cmd>test1</cmd> <cmd>test1 --help</cmd> <cmd>test1 --version</cmd> </sample> <sample name="test4"> <topic>This a test of the Test :-)</topic> <cmd>test1</cmd> <cmd>test1 --help</cmd> <cmd>test1 --version</cmd> </sample> </tests> </testunit>
$SessionID = GetSessionID($SessionName);
This function returns a unique session ID. The ID is build with this format: session-YYYYMMDD-HHMMSS-PID
@CmdOutput = ExecuteCmd($Cmd);
This function pass a command to the system and returns the command result in an array or returns nothing in case of error.
$SessionId = CreateSession($UnitName);
By defaut the session format name allows to run in multiuser environment (like CGI). All seesion are logged in 'session_history.log' which is located in output path directory.
This function registers a session by building an unique session ID based on current date. It also creates a directory to store tests results.
RegisterTestSample($SessionID, $Sample, $Topic, $Skipped);
This functions adds an entry to the 'result.xml' file in order to store test results of the sample. The status of the entry is initially set to 'running' except if $skipped is set to 'true'.
SaveCmdResult($Cmd, $FullPathCmdOutFile, @CmdOut);
This function stores @CmdOut in a file named $FullPathCmdOutFile. It also add extra informations to the file to make it match to the output format requirements. For example it adds <PRE></PRE> to permit a browser to display the file.
@CmdOut = RunTest($Session, $Sample, $Cmd);
This function execute $cmd and save the output in the current session directory.
my $pu = new SHX::PerlUnit($UnitName)
SHX::PerlUnit contructor which takes one optionnal argument $UnitName. If no argument is provided 'punit' is used.
The test unit description is an xml file named like the test unit followed by '.xml'.
$pu->SetSessionFormat("YYYYMMDD-hhmmss"); Y: year M: month D: day h: hour m: minutes s: seconds P: PID
'\{}[]()^$.|*+?/' will be changed to '_'
$pu->Load();
Loads the testunit config from the xml file given to the constructor and stores it in global hash %CONFIG.
Date format : YYYY-MM-DD
First Draft
Bug: Punit command line utility can'y find libs when executed outside its directory Fix: Findbin module used
Issue: user need to copy punit_to_html.xslt to 'output_path' Fix: moved to the same dir as PerlUnit.pm. Search path is @INC/SHX.
Bug: Under windows, when the commands are executed, path in command name needs '\' Fix: solved with : s/(\w)\/(\w)/$1\\$2/g if $ENV{OS} =~ /win/i Note: Not yet available for *nix platforms. Should test $ENV{OS}
Issue: Displays too much informations Fix: Changed some Info() to Debug()
Copyright 2002 SyntHeretiX Studio - Réda BOUREBABA <bzctoons@free.fr>
SHX::PerlUnit - API to perform regression tests on software units. |