Testing Records

Component Testing for Ada

To test all the fields of a structured variable or record, use a single STR instruction to define the initializations and expected values of the structure.

The STR 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 STR 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 STR instructions are located with respect to the test procedure call since the Ada code generator separates STR 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.

Example

The following example demonstrates typical use of the STR statement:

--procedure push(l: in out list; s:string);

TEST 2

FAMILY nominal

ELEMENT

VAR l, init = NIL, ev = NONIL

STR l.all, init == , ev = ("myfoo",NIL,NIL)

VAR s, init = "myfoo", ev = init

#push(l,s);

END ELEMENT

END TEST

Related Topics

Testing Records | Testing a Record with Ada Expressions | Testing a Record with Another Record | Testing Records with Discriminants | Testing Tagged Records | No Test