C++ Test Driver Script

Component Testing for C++

The C++ Test Driver Script stimulates the source code under test to test assertions on a cluster of classes.

The test driver script itself is contained in an .otd file and may call two optional files:

  • A declaration file (.dcl) that contains C++ code that ensures the types, class, variables and functions needed by your test script will be available in your code.

  • A stub file (.stb) whose purpose is to define variables, functions and methods which are to be stubbed.

Using a separate declaration and stub files is optional. It is possible to include all or certain declarations and stubs directly within the test driver script file.

C++ Contract Check scripts are written in C++ Contract Check Language, which is part of the C++ Test Script Language designed for Component Testing for C++.

A typical Component Testing .otd test script looks like this:

INCLUDE "Test.dcl";

TEST CLASS TestClass1 {

PROLOGUE {

<Declarations of variables>

<Actions to be performed before executing this test class.>

}

TEST CASE Test1 {

#method_under_test();

CHECK (expression_must_be_true == true);

}

EPILOGUE {

<Actions to be performed when leaving the test class>

}

RUN {

Test1;

}

}

RUN {

TestClass1 (File<char*>);

}

See the Reference section for the semantics of the C++ test driver language.

You can use the Component Testing wizard to set up a test node and create the C++ Test Driver script templates or you can manually create a Component Testing for C++ test node to reuse existing test scripts.

An .otc contract-check script must be executed before an .otd Test Driver script, therefore the order in which both script types appear in the Test node is critical. This is important if you are manually creating a test node.

See the Reference section for the semantics of the C++ Contract Check Language.

Related Topics

C++ Contract-Check Script | Component Testing Wizard | Using native C++ statements