Defining a new test generator

A test generator uses recorder packets and produces test-model elements that the test generator adds to the test model.

Before defining a test generator, you must identify the type of data that the generator can use and the type of model elements that the generator produces. The input data for a test generator can either be the raw data that the recorders produced, or data that has been altered during the conversion stage. The output elements of a test generator are typed by feature, which usually corresponds to a specific protocol.

To define a new test generator:

  • Declare a new test generator type in the plugin.xml file, using the com.ibm.rational.test.lt.testgen.core3.testGenerator extension point.
  • Assign the test generator a unique ID and a name.
  • Declare which packet types the test generator can use.
  • Declare the required properties of the packet stream that is sent to the test generator. The framework includes the necessary converters in the conversion stage so these properties are verified when the packets reach the test generator. For information on defining properties by using converters, see Defining a new packet converter.
  • Define an implementation class that implements the com.ibm.rational.test.lt.testgen.core.testgen.ITestGenerator interface.

The product includes a built-in converter that produces an ordered stream of packets that is based on start time stamps of the packets. Typically, recorders produce packets that are sorted by their end time stamps. Most test generators require that input packets be ordered by their start time stamps, so the packet stream must include the sorted property in the required properties.

Consider these facts about ITestGenerator implementations:

  • Typically, you extend the com.ibm.rational.test.lt.testgen.core.testgen.BaseTestGenerator class, which provides a basic implementation and only requires overriding the necessary methods.
  • The initialize() method is where any options from the test generator configuration are read using the getContext().getConfiguration() method.
  • The process() method is the most important. The framework calls this method for each input packet. This method creates model elements and adds the elements to the output test. Model elements must be added to the test using methods from the ITestStack object that is returned by the getContext().getStack() method.
  • The framework calls the complete() method after all packets have been sent to the test generator. The complete() method can be used for performing any post-processing operations.
  • Use the getContext().logMessage() method to report any messages from the test generator to the user, including error messages. If the message pertains to an unrecoverable error, the framework stops the test generation process.
Note: A test generator must not delay in adding elements to a test. Test generators must add elements to the test as soon as they are created. A test generator can still add data to an element after the element has been added to a test. If there are delays in adding elements to a test, generated elements might not be correctly ordered. For example, if another test generator also generates elements in a mixed protocol environment, or if the recording contains annotations, then the generated elements might not be in the correct order. If you still need to perform processing that would delay the insertion of an element into to the test (for example, accumulating data in order to build a higher-level object), write a converter that does the processing and insert this converter before the test generator starts.