Studio:TestCase.pm: Difference between revisions

From STRIDE Wiki
Jump to navigation Jump to search
m (Text replace - 'Category:Libraries' to 'Category:Studio:Libraries')
 
Line 106: Line 106:
:Text of the comment to be added.
:Text of the comment to be added.


[[Category:Libraries]]
[[Category:Studio:Libraries]]

Latest revision as of 23:25, 20 August 2009

Example

use strict;
use warnings;
use diagnostics;
use Carp;
use Win32::TieRegistry(Delimiter=>"/");
use File::Spec;
use Win32::OLE;
Win32::OLE->Option(Warn => 3);

# setup the lib path
use vars qw(
    $studio
    $testSuite
    $ascript
    $StrideDir
    $StrideLibDir
);
BEGIN {
    $StrideDir =  
        $Registry->{"LMachine/SOFTWARE/S2 Technologies/STRIDE/InstallDir"} ||
        $ENV{'STRIDE_DIR'} ||
        'C:\\STRIDE';
    $StrideLibDir = File::Spec->catdir($StrideDir, 'lib', 'perl');
}

###############################
# Imported Libs 
###############################
use lib $StrideLibDir; # Use the above calculated path to finf the lib's

use S2S::TestCase;


$main::testSuite->Tests->RemoveAll();

my $tc1 = S2S::TestCase->new('testcase 1', 'description: testcase 1');
$tc1->passTest();

my $tc2 = S2S::TestCase->new('testcase 2', 'description: testcase 2');
$tc2->addInfo('Separate info comment');
$tc2->passTest('info comment gets added');

my $tc3 = S2S::TestCase->new('testcase 3', 'description: testcase 3');
$tc3->failTest();

my $tc4 = S2S::TestCase->new('testcase 4', 'description: testcase 4');
$tc4->addError('Separate error comment');
$tc4->failTest('error comment gets added');

Description

This module provides a thin wrapper over the reporter::TestCase object to provide some convenience functions.

Instance Methods

new($name[, $description, $parentsuite])

Creates an instance of the TestCase object, performing the following:

  • Creates a new test case with the name as specified by the $name argument as a child of the specified $parentsuite. (Or if the specified test case already exists, uses it.)
  • Sets the test case description using the $description argument; if the test case already exists and has a non-empty description, $description is appended to the existing text.
$name
Name of the test case to be wrapped by this object; if the test case already exists as a child of $parentsuite, it will be used, otherwise a new test case is created.
$description
[optional] Description to be added to the specified test case, If the test case already exists and has a non-empty description, $description will be appended to the existing text with a ' | ' separator.
$parentsuite
[optional] Parent suite of the target test. If omitted this value defaults to $main::testSuite, which is the suite corresponding to the workspace folder that the using script belongs to.

getInternalTestCase()

Returns the Resporter::TestCase object wrapped by this object

failTest([$failMessage])

Sets the status of the wrapped testcase to "FAIL" and optionally adds an Error comment

$failMessage
[optional] If provided, this string will be added as a comment to the test case with the label "Error".


passTest([$passMessage])

Sets the status of the wrapped testcase to "PASS" and optionally adds an Info comment.

$passMessage
[optional] If provided, this string will be added as a comment to the test case with the label "Infor".

addError([$comment])

Adds a text comment to the test case with the label "Error".

$comment
Text of the comment to be added.

addInfo([$comment])

Adds a text comment to the test case with the label "Info".

$comment
Text of the comment to be added.