Working with Test Scripts

prevnext

If you want to trap certain errors but you want the log to reflect a Fail result for the test script, use one of the Test Script Services logging methods to log the Fail result.Manipulating Environment Variables


During execution of a test script, the behavior of virtual testers is controlled by environment variables. This design makes it possible for you to test different assumptions or scenarios with the same test script, by modifying the values of the environment variables. An example follows. If executed from TestManager, the example would produce this output in the virtual tester output file:

At start, value is 'CONSTANT'
After push, value is 'NEGEXP'
After pop, value is 'CONSTANT'
After set, value is 'NEGEXP'
After save and reset, value is 'CONSTANT'
After restore, value is 'NEGEXP'

Here's the Java code. The classes and methods are documented in TSSMeasure.EnvironmentOp.

import java.io.*;
import com.rational.test.tss.*;

public class EnvOpTest extends com.rational.test.tss.TestScript {

    public static void main(String[] args) {
        EnvOpTest eot = new EnvOpTest();
        eot.testMain(args);
    }

    public void testMain(String[] args) {
        try {
            StringBuffer sb = new StringBuffer();
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("At start, value is `" + sb.toString()+ 
"`");

            TSSMeasure.environmentOpSetStringValue(
                EVAR_Think_dist,
                EVOP_push,
                new StringBuffer("NEGEXP"));
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("After push, value is `" + 
sb.toString()+ "`");

            TSSMeasure.environmentOp(
                EVAR_Think_dist,
                EVOP_pop);
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("After pop, value is `" + sb.toString()+ 
"`");

            TSSMeasure.environmentOpSetStringValue(
                EVAR_Think_dist,
                EVOP_set,
                new StringBuffer("NEGEXP"));
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("After set, value is `" + sb.toString()+ 
"`");

            TSSMeasure.environmentOp(
                EVAR_Think_dist,
                EVOP_save);
            TSSMeasure.environmentOp(
                EVAR_Think_dist,
                EVOP_reset);
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("After save and reset, value is `" +
                               sb.toString()+ "`");

            TSSMeasure.environmentOp(
                EVAR_Think_dist,
                EVOP_restore);
            TSSMeasure.environmentOpGetStringValue(
                EVAR_Think_dist,
                EVOP_eval,
                sb);
            System.out.println("After restore, value is `" +
                               sb.toString()+ "`");
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

prevnext


Rational Test Script Services for Visual Basic Rational Software Corporation
Copyright (c) 2001, Rational Software Corporation http://www.rational.com
support@rational.com
info@rational.com