SHX::PerlUnit - API to perform regression tests on software units.


SYNOPSIS

  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.


DESCRIPTION

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 file describing the Test Unit

 <?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>


FUNCTIONS (private interface)

GetSessionID

  $SessionID = GetSessionID($SessionName);
SessionName
The name of the session to build the name for.

SessionID
Returned session unique ID

This function returns a unique session ID. The ID is build with this format: session-YYYYMMDD-HHMMSS-PID

ExecuteCmd

  @CmdOutput = ExecuteCmd($Cmd);
Cmd
System command to execute

CmdOutput
Returned array contaning the output of the command

This function pass a command to the system and returns the command result in an array or returns nothing in case of error.

CreateSession

  $SessionId = CreateSession($UnitName);
UnitName
The name of the test unit to buid an ID for

SessionId
The unique ID of this session : UnitName-YYYYMMDD-hhmmss-PID

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

  RegisterTestSample($SessionID, $Sample, $Topic, $Skipped);
SessionID
Session ID. TODO: should be removed in pure OO API version

Sample
The sample name.

Topic
The description of the sample.

Skipped
If set to 'true' the sample testing is 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

  SaveCmdResult($Cmd, $FullPathCmdOutFile, @CmdOut);
Cmd
The command to store output of.

FullPathCmdOutFile
Full name of the file to the save the output in.

CmdOut
Array containg the command output.

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.

RunTest

  @CmdOut = RunTest($Session, $Sample, $Cmd);
Session
Session ID. TODO: should be removed in pure OO API version

Sample
The sample name.

Cmd
A sytem command to execute.

CmdOut
Returns an array containing the command output

This function execute $cmd and save the output in the current session directory.


METHODS

new

  my $pu = new SHX::PerlUnit($UnitName)
UnitName
Optional test unit name. Default is 'punit'.

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'.

SetSessionFormat

  $pu->SetSessionFormat("YYYYMMDD-hhmmss");
  Y: year
  M: month
  D: day
  h: hour
  m: minutes
  s: seconds
  P: PID

'\{}[]()^$.|*+?/' will be changed to '_'

Load

  $pu->Load();

Loads the testunit config from the xml file given to the constructor and stores it in global hash %CONFIG.

Run


CHANGELOG

Date format : YYYY-MM-DD

punit-2002-08-01, v0.10
  First Draft
punit-2002-08-02
  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()


TODO


COPYRIGHT

Copyright 2002 SyntHeretiX Studio - Réda BOUREBABA <bzctoons@free.fr>

 SHX::PerlUnit - API to perform regression tests on software units.