Environment override

Component Testing for C

To provide more flexibility in using environments, you can override the initialization and test specifications in an ENVIRONMENT block for one or more variables, one or more array elements, or one or more fields of a structured variable by using either of the following:

  • A new environment

  • The instructions VAR, ARRAY, or STR in the ELEMENT block

The ENVIRONMENT concept greatly improves test robustness. You can use this approach to group default initialization and test specifications with all the variables that are global to a module under test, allowing you to check that unexpected global variables in tests on a service are indeed not modified.

The following steps are used to handle environments:

  • VAR, ARRAY and STR instructions are stored between ENVIRONMENT and END ENVIRONMENT instructions.

  • When the Test Script Compiler comes across the instruction USE, it determines the scope of the environment that has been stored.

  • At every END ELEMENT instruction, the Test Script Compiler browses through all visible environments beginning with the most recently declared one. The Test Script Compiler then checks every environment variable to see if it has been fully or partially tested. If it has only been partially tested, the Test Script Compiler generates the necessary tests to complete the testing of the variable.

This process means that:

  • Tests linked to environments are always carried out last.

  • The higher the environment's precedence, the earlier the tests it contains will be carried out.

Example

The following example illustrates an override of an array element in two tests:

TEST 1

FAMILY nominal

ELEMENT

VAR histo[0], init = 0, ev = SIZE_IMAGE*SIZE_IMAGE

#status = compute_histo(x1,y1,x2,y2,histo);

END ELEMENT

END TEST

TEST 2

FAMILY nominal

ELEMENT

ARRAY image, init = {others => {others => 100}}, ev = init

ARRAY histo[100], init = 0, ev = SIZE_IMAGE*SIZE_IMAGE

#status = compute_histo(x1,y1,x2,y2,histo);

END ELEMENT

END TEST

In the first test, only histo[0] has an override. Therefore, all the default tests were generated except for the test on the histo variable, which had its 0 element removed, and a test was generated on histo[1..255].

In the second test, the override is more noticeable; the histo[100] element has been removed to generate two tests: one on histo[0..99], and the other on histo[101..255].