Extended Test Script Services Reference |
This class lets you log information from test scripts and stubs.
The TestLog
class extends the class com.rational.test.tss.TSSLog
.
public class TestLog com.rational.test.ct.TestLog
Commonly used with QualityArchitect.
QualityArchitect is required for use of this class.
The following sample code uses the writeException()
method to report an exception with a datapool operation. The example also uses the message()
method from the extended TssLog
class to log a number of status messages at various stages of the datapool operation. You can find examples of other TestLog
methods in the section LookUpTable Example.
public void testMain(String[] args) { boolean fRetval = false; TSSDatapool dp = new TSSDatapool(); int iDPCount = 0; try { // In+itialize test services tms.startTestServices(); // Initialize arguments, to double getBalance(long accountID, // java.lang.String acctType) method long accountID = 0; java.lang.String acctType = null; double expectedReturn = 0.0; double actualReturn = 0.0; String sExpectedException = ""; InitialContext initContext = getInitialContext(); // TODO: the generated JNDI context name is defaulted to be the // Remote Interface Name. Please replace with appropriate JNDI // context name for your needs, if you have deployed the EJB in // some other JNDI subcontexts. Object o = initContext.lookup("ExecuteTransaction"); ExecuteTransactionHome home = (ExecuteTransactionHome) PortableRemoteObject.narrow(o, ExecuteTransactionHome.class); // Declare arguments to the create method // Invoke the create method. ExecuteTransaction remote = home.create(); String sDPName = "ExecuteTransaction_getBalance_D"; dp.open(sDPName); fRetval = dp.fetch(); while (fRetval) { iDPCount = iDPCount + 1; // Retrieve values from Datapool... accountID = dp.value("accountID").longValue(); acctType = dp.value("acctType").toString(); expectedReturn = dp.value("expectedReturn").doubleValue(); sExpectedException = dp.value("expectedException").toString(); try { // Test double getBalance(long accountID, java.lang. // StringacctType) actualReturn = remote.getBalance(accountID, acctType); if (sExpectedException.equals("")) { if (expectedReturn == actualReturn) TestLog.message("Expected result",TSS_LOG_RESULT_PASS, "Call to getBalance returned expected value"); else TestLog.message("Unexpected result", TSS_LOG_RESULT_FAIL,"Call to getBalance returned unexpected value, " + (new Double(actualReturn)) .toString() + "."); } else { TestLog.message("Unexpected result", TSS_LOG_RESULT_FAIL, "Expected exception, "+ sExpectedException + " was not thrown."); } } catch (Exception e) { if (e.getClass().getName().equals(sExpectedException)) { // Expected exception occurred. Log success. TestLog.message("Expected result", TSS_LOG_RESULT_PASS, "Expected exception, " + sExpectedException + " was thrown."); } else { TestLog.message("Unexpected result", TSS_LOG_RESULT_FAIL, "Unexpected exception, " + e.getClass().getName() + " was thrown."); } } fRetval = dp.fetch(); } if (iDPCount == 0) { // Datapool did not contain any rows. Log a warning. TestLog.message("Empty Datapool", TSS_LOG_RESULT_WARN, "Datapool, " + sDPName + " is empty."); } } catch (Throwable e) { TestLog.writeException(e); } finally { dp.close(); tms.endTestServices(); } }
This class contains the following methods:
writeException()
Lets you log an exception that was thrown in a test script.
writeStubException()
Lets you log information about an exception that was thrown during the execution of a QualityArchitect stub.
writeStubMessage()
Lets you log a message relating to the execution of a QualityArchitect stub.
Note: In addition to these methods, you can also use the methods in the TSSLog
class, as summarized in section Logging Class.
public TestLog
()
Lets you log an exception that was thrown in a test script.
public static booleanwriteException
(java.lang.Exceptione
)
true
if the log attempt was successful, and false
if the log attempt failed.
This method logs a Fail result for the test script.
For an example of this method, see TestLog Example.
Lets you log information about an exception that was thrown during the execution of a Rational QualityArchitect stub.
public static voidwriteStubException
(java.lang.Stringdescription
, java.lang.Exceptione
)
description
A description of the exception.
e
The exception to log.
This method throws the following exception:
If you handle this exception and do not log it, TestManager will not be aware of the exception and will not log a Fail result for it. The script will continue to run, and TestManager could log a Pass Result for the script.
The description appears in the Description field of the Log Event Properties dialog box.
For examples of this method, see LookUpTable Example.
Lets you log a message relating to the execution of a Rational QualityArchitect stub, and also a description of the message.
public static voidwriteStubMessage
(java.lang.Stringmessage
, java.lang.Stringdescription
)
message
The message to insert into the log.
description
A description of the message. The description lets you expand upon the logged message.
The message appears in the Log Event column of the LogViewer. The description appears in the Description field of the Log Event Properties dialog box.
For examples of this method, see LookUpTable Example.
Rational Test Script Services for Java | Rational Software Corporation |
Copyright (c) 2003, Rational Software Corporation | http://www.rational.com support@rational.com info@rational.com |