Using Structs, CompoundValues, and Classes

There are a number of different ways to collect multiple values into a single object. In this topic we discuss the differences between structs, classes, and the CompoundValue type from the Spec Explorer modeling perspective. Remember that the end result of modeling and exploration is the creation of test cases for checking system under test (SUT) conformance.

The tests that Spec Explorer creates can handle all the above types with equal facility. However, the selection of a particular type for your model program depends on what you want to test.

You use a struct when you want to ensure that the same structured values that appear in model exploration will be sent and received by the test steps at test runtime. It is not necessary for these structs to be created and returned by the SUT before they are used by the test, as the created test code will create the structs with the exact same contents as the model uses. The test code will pass these structs to the SUT. For structs returned by the SUT, the test code will compare the contents of the structs returned by the SUT to the structs generated in the model exploration.

Compound values (that is, types derived from CompoundValue) are handled exactly the same way during testing as structs are. The only difference is that structs cannot be recursive; that is, used to model data structures such as linked lists and trees.

You use a class in your model when you care about object equality during testing. If a step in your model exploration passes the same object that was returned in the previous step, the test code will guarantee equality. Note that this does NOT compare the internal data in the class. Instances MUST be explicitly returned by the SUT in a previous step, instances are not created by test code.

See Also