5.9. How to Use Test Statements

This section discusses the API Squish offers to perform tests that will create test results. Verification points also use this test API; more coverage of verification points is given in the How to Create and Use Verification Points (Section 5.22) section. Working with the test result log is discussed in the Processing Test Results (Section 7.1.3) section.

To compare two values and write the result of the comparison to the test log, use the test.compare function. To simply check that something is true (i.e., to check a Boolean value), use the test.verify function. To write some neutral information to the test log at a particular point in the test run, use the test.log function, and to write a warning to the test log use the test.warning function.

Here are a few examples that show how to use these functions.

Python
lineedit = waitForObject(":Address Book - Add.Forename:_QLabel")
test.verify(lineedit.enabled)
test.compare(lineedit.text, "Jane")
test.log("Important note", "This is an important note about the test")
test.warning("Suspicious warning",
        "This test is incomplete and should be extended!")
JavaScript
var lineedit = waitForObject(":Address Book - Add.Forename:_QLabel");
test.verify(lineedit.enabled);
test.compare(lineedit.text, "John");
test.log("Important note", "This is an important note about the test");
test.warning("Suspicious warning",
        "This test is incomplete and should be extended!");
Perl
my $lineedit = waitForObject(":Address Book - Add.Forename:_QLabel");
test::verify($lineedit->enabled);
test::compare($lineedit->text, "Jane");
test::log("Important note", "This is an important note about the test");
test::warning("Suspicious warning",
        "This test is incomplete and should be extended!");
Ruby
lineedit = waitForObject(":Address Book - Add.Forename:_QLabel")
Test.verify(lineedit.enabled)
Test.compare(lineedit.text, "Jane")
Test.log("Important note", "This is an important note about the test")
Test.warning("Suspicious warning",
        "This test is incomplete and should be extended!")
Tcl
set lineedit [waitForObject ":Address Book - Add.Forename:_QLabel"]
test verify [property get $lineedit enabled]
test compare [property get $lineedit text] "John"
test log "Important note" "This is an important note about the test"
test warning "Suspicious warning" \
        "This test is incomplete and should be extended!"

Both the test.log and test.warning functions can be given either one or two arguments, the first is the “message” text, and the optional second argument can be used to provide additional details.

Many other test functions are available, including ones for verifying expected failures and expected exceptions, and various functions for writing messages to the test log. The complete API is documented in the Verification Functions (Section 6.3.8) section in the Tools Reference Manual (Chapter 7).