TestCase |
![]() |
TestCase - class representing a test case
Shane P. McCarron <shane@aptest.com>
Copyright 2002-2006 Applied Testing and Technology, Inc. All Rights Reserved.
use TestCase;
Create an empty test case
my $case = new TestCase();
get the value of a field
$value = $case->valueOf(field)
set the value of a field
$value = $case->valueOf(field, value)
get/set the location of the test case
$value = $case->path(value)
save the Test Case
$res = $case->save();
The TestCase object permits creation of/access to a test case and its contents. Such objects can be sued to create new test cases, read existing test cases, or update existing test cases.
The data structure uses hashs to capture the majority of the field data. However, since field data is "ordered", there is also an index array that keeps track of the order in which the data was read/created, and should be emitted if the save or print methods are called.
$tc = new TestCase()
$tc = new TestCase(suite)
$tc = new TestCase(suite, name)
$tc = new TestCase(suite, name, readWrite)
$tc = new TestCase(suite, name, readWrite, testDbHandle)
suite is the test suite in which we are operating
name is the name of the test in that suite
readWrite is a boolean that indicates whether the object should be writeable.
testDbHandle is a ref to a TestDB object. If it is not provided, a testDB will be opened, used, and released automatically.
schema is a ref to a Schema object. If it is not provided, one will be opened, used, and released automatically.
$tc = new TestCase(suite, UUID)
$tc = new TestCase(suite, UUID, readWrite)
$tc = new TestCase(suite, UUID, readWrite, testDbHandle)
suite is the test suite in which we are operating
UUID is the UUID of the test in that suite
readWrite is a boolean that indicates whether the object should be writeable.
testDbHandle is a ref to a TestDB object. If it is not provided, a testDB will be opened, used, and released automatically.
schema is a ref to a Schema object. If it is not provided, one will be opened, used, and released automatically.
generateMarkup walks through all the fields defined in a test case, emitting the HTML associated with those fields. It does this in SCHEMA order, regardless of the order of the fields in the test case itself.
$output = $tc->generateMarkup(template, showValues, showLabels);
template is the template to populate.
showValues is a boolean flag that indicates whether the values of session variables should be interpolated. If true, values are ONLY interpolated if there is also a session associated with this test case object.
showLabels is a boolean flag indicating whether field labels should be included in the output.
fieldList is a comma-separated list of field names in which values should be highlited if they are present.
pattern is a reference to a hash describing the pattern to highlight. The hash has three elements; pat is a string; isRE indicates if it is a regular expression; isCaseSensitive indicates if it is case sensitive.
returns the generated output, or undef if the output could not be generated.
$tc->dirtyFlag();
$tc->dirtyFlag(1|0) ;
Calling this method with no arguments will return whether or not any data has changed since the ojbect was originally created.
When ever you DO change part of the object (most notably "data") you should call this method with the true value.
$last = $tc->lastValueOf(field) ;
Returns the last value of a field. If the field is NOT in a table, just returns the field's value. If the field does not exist, or the field has no value, returns undef.
$tc->populate() ;
Selects random values for all menu fields. Creates random text content for text fields, and random paragraphs for textareas. For tables, ensures that there are several rows
$boolean = $tc->fromDisk();
Returns a boolean indicating whether or not the test was read from its source file on the disk.
$id = $tc->id(path);
Returns the current setting of the special Id field of the object.
If path is defined, sets the contents of the Id field according to path.
$ident = $tc->identifier(myID);
Returns the current setting of identifier. Currently this is the same as the name of the test, but in the future it will be the UUID. We introduced this abstraction in version 2.13 so that libraries could start using it in anticipation of migrating later.
If path is defined, sets the contents of the Id field according to path.
$time = $tc->mtime();
$time = $tc->mtime(time);
$path = $tc->path()
Really a no-op, since this object does not have a database.
my $sbRef = tcRef->sandbox( sbRef ) ;
Returns a reference to a sandbox object.
# save a test that was read from disk initially
# note that if it was NOT opened for writing initially, this might not work.
$res = $tc->save();
# save a test case that was read from disk, and use the Schema defined order
# for the fields
$res = $tc->save(1);
# save a test that was created in memory (or to an alternate location)
$res = $tc->save(useSchema, path);
returns 1 if the save succeeded.
my $schema = new Schema();
my $tc = new TestCase();
$tc->schema($schema);
If this method is called with a handle, it is assumed to be a handle to a schema object.
Otherwise, it will check to see if a schema has already been associated with this test case. If not, it will get one.
Returns a handle to the schema associated with this object.
If this method is called with a handle, it is assumed to be a handle to a TestSession object.
Returns a handle to the schema associated with this object.
$uuid = $tc->UUID() ;
returns the value of the UUID field from the testcase. If there is not yet a UUID field, creates a new UUID for the test case, updates the test case, and returns that value.
returns undef if the test case was not opened in write mode or if we no longer have a handle to a test database AND we need to create the UUID.
$val = $tc->rawValue(field);
returns the value of the field.
$val = $tc->valueOf(field);
$val = $tc->valueOf(field, value);
returns the value of the field. If the field was not previously defined, then the value is set AND the field is appended to the ordered list of fields in $tc->{fields}.
If the value is a "list" field according to the schema, then we use the schema object to reorder the values into a legal set that is in the schema defined order BEFORE we store it.
Copyright © 2000-2006 Applied Testing and Technology, Inc. All rights reserved.