Testing variables

Component Testing for C

One of the main features of Component Testing for C is its ability to compare initial values, expected values and actual values of variables during test execution. In the C Test Script Language, this is done with the VAR statement.

The VAR statement specifies both the test start-up procedure and the post-execution test for simple variables. This instruction uses three parameters:

  • Name of the variable under test: this can be a simple variable, an array element, or a field of a record. It is also possible to test an entire array, part of an array or all the fields of a record.

  • Initial value of the variable: identified by the keyword INIT.

  • Expected value of the variable after the procedure has been executed: identified by the keyword EV.

Declare variables under test with the VAR statement, followed by the declaration keywords:

  • INIT = for an assignment

  • INIT == for no initialization

  • EV = for a simple test.

It does not matter where the VAR instructions are located with respect to the test procedure call since the C code generator separates VAR instructions into two parts :

  • The variable test is initialized with the ELEMENT instruction

  • The actual test against the expected value is done with the END ELEMENT instruction

Many other forms are available that enable you to create more complex test scenarios.

Using C Expressions

Component Testing for C allows you to define initial and expected values with standard C expressions.

All literal values, variable types, functions and most operators available in the C language are accepted by Component Testing for C.

Example

The following example demonstrates typical use of the VAR statement

HEADER add, 1, 1

#with add;

BEGIN

SERVICE add

# a, b, c : integer;

TEST 1

FAMILY nominal

ELEMENT

VAR a, init = 1, ev = init

VAR b, init = 3, ev = init

VAR c, init = 0, ev = 4

#c := add(a,b);

END ELEMENT

END TEST

END SERVICE

Related Topics

Testing intervals | Testing tolerances | Initializing without testing | Testing expressions | Declaring parameters | Testing arrays | Testing structured variables