C++ test driver script structure

A Component Testing for C++ test driver script (.otd script) describes a test driver. Its purpose is to stimulate the tested classes by creating objects and calling their methods. It provides different ways to check that the objects behavior is the one that was expected.

When executed, the script is translated into a C++ source by Component Testing for C++. Furthermore, it instruments the source code under test whenever the STUB, CHECK STUB, or CHECK METHOD statements are used.

Order is meaningful for INCLUDE and native statements. RUN may appear only once in a C++ Test Driver script. Other entities are not ordered: for instance, a TEST CLASS can forward-reference a STUB.

Note A C++ Test Driver script is made both of statements and instructions. Instructions are ordered: their relative position is meaningful. Statements have no order: they have a declarative nature.

Basic structure

A typical Component Testing .otd test script structure could look like this:

TEST CLASS TestAnyPhilosopher (Philosopher_type)

{

TEST CLASS TestNominal (Philosopher_type)

{

PROLOGUE

{

// Actions to be performed when entering this test class.

}

TEST CASE AssignForks

{

// CHECK statements

}

EPILOGUE

{

// Actions to be performed when leaving this test class.

}

RUN

{

// Runs the test cases

}

}

RUN

{

// Runs the test class

}

All instructions in a test script have the following characteristics:

  • All statements begin with a keyword.

  • Statements are not case sensitive (except when C expressions are used).

  • Statements start at the beginning of a line and end at the end of a line. You can, however, write an instruction over several lines using the ampersand (&) continuation character at the beginning of additional lines. In this case, the ampersand must be the very first character on that line; no spaces or tabs should precede it.

  • Statements must be shorter than 2048 characters, although this limit may be lower on some platforms.

Structure statements

The following statements allow you to describe the structure of a test.

  • TEST CLASS:Describes an object test class, which is one of the structuring entities of a C++ test driver script. Test classes can appear at the root-level of a C++ Test Driver Script and in test classes.

  • PROLOGUE: Defines native code that is to be executed whenever the surrounding test class execution begins. This code is executed before any other of the test class' components.

  • TEST CASE: Describes an object test case, which is the smallest testing structure in a hierarchical C++ test driver script. Test cases appear in test classes and test suites.

  • EPILOGUE: Defines native code that is to be executed whenever the execution of the surrounding test class ends. This code is executed after other test class components.

  • RUN:Defines the behavior of the surrounding test class.

Related Topics

TEST CLASS | PROLOGUE | TEST CASE | EPILOGUE | RUN