Tool Mentor: Implementing Developer Tests using Rational Test RealTime
This tool mentor describes how to implement tests using RationalTest RealTime.
Tool: Rational Test RealTime
Relationships
Main Description

Overview

Test RealTime integrates three testing tools:

  • Unit Testing automates C and Ada software component testing.
  • Object Testing is an object-oriented approach to behavior testing of C++ code.
  • System Testing is a powerful environment for testing message-based applications.

The choice of which testing tool you should use with your application depends on the development environment and the nature of the application. For each testing tool, you need to develop a dedicated test script.

Before writing the actual tests for your application, Test RealTime requires that you create the test project and link the project to the application under test.

Tool Steps

To create a test script in Test RealTime, perform the following actions:

  1. Run the Component Testing Wizard
  2. Enter test data and expected results
  3. Modify stub behavior

1. Run the Component Testing Wizard

Test RealTime provides a component testing wizard which, when executed, analyzes specified source code and generates a fully executable test harness. All that remains for the developer to ensure the target code is tested as intended is to define stub behavior (see second Tool Step) and enter test data and expected results (see third Tool Step).

NOTE: It is not required that the component testing wizard be used - all files and code necessary to support a test can be generated by hand. The wizard, however, can save a significant amount of effort. Either way, test execution and test reporting are automated.

The component testing wizard can be accessed in one of two ways. Either method assumes that a Test RealTime project has already been opened

  • Select the Activities link located on the left-hand side of the Test RealTime Start Page. Selection of this link brings up a list of the three primary activities that can be chosen by the developer. To perform component testing, the developer should now select the Component Testing link.

  • Right-click any source file/class/method/function/procedure in the Asset Browser of the Project Window located on the right-hand side of Test RealTime. Selection of the Test... option in the popup menu opens the component testing wizard.

The primary difference between these two methods of initiating the component testing wizard is that the first option requires the user to select the source file(s) containing the functions/methods/procedures to be tested - the second option already knows what source file will be used and thus skips the initial steps of the component testing wizard.

In either case, the developer will be asked to select a Test Mode - either Typical or Expert. The difference is related to desired stubbing behavior. As a reminder, a stub is "a component containing functionality for testing purposes" - that is, a component designed to act in a predefined way to facilitate the testing of some other system component. In Typical Mode, Test RealTime will automatically generate a stub template for any function/method/procedure explicitly referenced in the selected source file(s). Expert Mode allows you to additionally select components not explicitly referenced in the chosen source file(s). Either way, the actual functionality of these stubs are defined later - see the second Tool Step below.

Once the wizard has been executed to its conclusion, Test RealTime creates a node within the active project. This node contains a reference to the selected source file(s) as well as to the files required for test harness creation. These additional files need to be modified in order to:

  • define stub behavior
  • specify date used to drive the functions/methods/procedures under test
  • specify expected results for each input data set

For C, C++ and Ada, the test harness, test stubs and test script languages were built by Rational Software to accommodate the specific intricacies of those languages. For Java, Test RealTime uses Java as the test script language and bases its test harness and test stub frameworks on the JUnit framework (http://www.junit.org).

book icon For detailed information refer to the Rational Test RealTime User Guide, the chapter Graphical User Interface->Activity Wizards->Component Testing Wizard.

2. Enter test data and expected results

The test scripts generated by the component testing wizard can execute immediately. However, until the developer specifies the actual data with which to drive the component under test - as well as the expected output values -the test will not be very useful nor informative.

Each language supported by Test RealTime facilitates test creation in a different manner; each approach has been optimized for the unique characteristics of each language. C++ is further unique in that not only can standard tests be generated and executed, but optional contract checks can be made as well. Contract checks act like assertions - they are used to verify items such as pre/post-conditions and invariants.

book icon For detailed information related to C and Ada, refer to the following chapter in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for C and Ada->C and Ada Test Script->Overview->Test Script Structure
  • Automated Testing->Component Testing for C and Ada->C and Ada Test Script->Ada

    book icon and refer to the following chapters in the Rational Test RealTime Reference Guide

  • Component Testing Scripting Languages->C Test Script Language->C Test Script Language Keywords->ELEMENT...END ELEMENT
  • Component Testing Scripting Languages->C Test Script Language->C Test Script Language Keywords->ENVIRONMENT...END ENVIRONMENT
  • Component Testing Scripting Languages->Ada Test Script Language->Ada Test Script Language Keywords->ELEMENT...END ELEMENT
  • Component Testing Scripting Languages->Ada Test Script Language->Ada Test Script Language Keywords->ENVIRONMENT...END ENVIRONMENT

book icon For detailed information related to C++, refer to following chapters in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for C++->C++ Testing Overview

    book icon and refer to the following chapters in the Rational Test RealTime Reference Guide

  • Component Testing Scripting Languages->C++ Test Script Language->C++ Test Driver Scripts

book icon For detailed information related to Java, refer to following chapters in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for Java->Java Testing Overview->About JUnit

    book icon and refer to the following chapters in the Rational Test RealTime Reference Guide

  • Component Testing Scripting Languages->Java Test Primitives

3. Modify stub behavior

Components are designed to act in a particular manner. These components, regardless of their level of granularity, should respond to a given set of inputs with a particular, predefinable set of outputs. "Predefinable" means the results can be specified, either explicitly or algorithmically, prior to test execution.

Very often, components require the assistance of other components within the system in order to perform their functionality. These other components can be as simple as an additional function or as grandiose as an entire subsystem located somewhere else in the system. Either way, it is not uncommon for a developer to discover that their efforts at component testing are hampered by the fact that the components upon which their code relies do not yet exist, or at least are not yet reliably functioning. The act of stubbing compensates for this difficulty. (In fact, stubbing can be used to guarantee proper functioning by eliminating all reliance on third-party code.)

It is the responsibility of the developer to properly simulate components upon which the component under test relies. Proper simulation means that the stubbed functionality must be sufficiently accurate to ensure that the success or failure of the component under test can always be traced to the component itself, rather than to incorrect information produced by the stubs.

Rational Test RealTime facilitates the creation of stubs via the supported test scripting languages. In particular, for information about the creation of test stubs:

book icon For detailed information related to C and Ada, refer to the following chapter in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for C and Ada->C and Ada Test Script->Simulations->Stub Simulation Overview

    book icon and refer to the following chapters in the Rational Test RealTime Reference Guide

  • Component Testing Scripting Languages->C Test Script Language->C Test Script Language Keywords->STUB
  • Component Testing Scripting Languages->Ada Test Script Language->Ada Test Script Language Keywords->STUB

book icon For detailed information related to C++, refer to following chapters in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for C++->C++ Testing Overview->C++ Test Driver Script

    book icon and refer to the following chapters in the Rational Test RealTime Reference Guide

  • Component Testing Scripting Languages->C++ Test Script Language->C++ Test Script Keywords->STUB

book icon For detailed information related to Java, refer to following chapters in the Rational Test RealTime User Guide:

  • Automated Testing->Component Testing for Java->Java Testing Overview->Java Stub Harness

For More Information

For detailed information on how to run the test campaign, refer to the Tool Mentor titled Executing Tests Using Rational Test RealTime.