Object Diagrams  «Prev  Next»
Lesson 4A simple test
ObjectiveApply Object Diagrams to test Class Diagrams

Apply Object Diagrams to test Class Diagrams

In the vast arena of UML (Unified Modeling Language), the synergy between object diagrams and class diagrams is particularly significant. For a UML modeler, understanding how to employ object diagrams to validate and test class diagrams is essential. This comprehensive guide elucidates this intricate process.
  1. Establish the Context: Before diving into testing, you must clearly define the context. Understand the system's requirements, its expected behavior, and the specific scenarios you aim to test using the object diagrams.
  2. Construct Preliminary Object Diagrams: Based on the class diagram, generate a series of object diagrams that represent possible states or instances of the system. These object diagrams will reflect various scenarios and use cases, translating class definitions into tangible instances.
  3. Scenario Testing:
    1. Scenario Identification: Break down the system's operation into individual scenarios or use cases.
    2. Object Instance Creation: For each scenario, craft an object diagram that portrays the objects involved, their states, and their interactions.
    3. Comparison with Class Diagram: Validate whether each object in the diagram correctly adheres to its class definition in the class diagram. This includes attribute values, associations, and other relationships.
  4. State Validation: Using the object diagrams, ensure that each object's state aligns with its class constraints. If an object's state deviates from what's permissible by its class definition, it can point to missing constraints or the need for refinement in the class diagram.
  5. Association and Link Verification: For every association depicted in the class diagram, the object diagram should be able to represent corresponding links between object instances. If it's challenging to create links in the object diagram based on class associations, this might indicate ambiguities or inaccuracies in the class diagram's associations.
  6. Multiplicity Constraints: Ensure that the number of object links in the object diagrams adheres to the multiplicity constraints specified in the class diagram. Any deviation implies that the class diagram's constraints might be incorrectly defined or need better clarity.
  7. Role Testing: If roles are defined in the associations of the class diagram, the object diagram should reflect these roles in the links between objects. Validate that the roles are correctly manifested in the instances of the object diagrams.
  8. Iterative Refinement: It's essential to embrace an iterative approach. As you construct and validate object diagrams against the class diagram, discrepancies or ambiguities might emerge. Refine the class diagram based on these findings, and then retest using the object diagrams. This iterative cycle ensures comprehensive testing and refinement.
  9. Documentation: For every discrepancy, ambiguity, or refinement identified during the testing process, maintain detailed documentation. This documentation serves as a reference for stakeholders, aids in refining the class diagram, and assists in future testing endeavors.
  10. Collaboration and Review: Engage with stakeholders, developers, or other UML modelers to review the object diagrams and the discrepancies identified. Collaborative reviews can provide fresh perspectives, uncovering nuances or issues that might have been initially overlooked.
In UML modeling, object diagrams serve as a dynamic, instance-centric lens through which the static structure of class diagrams can be tested and validated. By systematically constructing, comparing, and refining these diagrams, a UML modeler can ensure the integrity, accuracy, and clarity of the modeled system, ultimately leading to robust and reliable system designs.

A Valuable Testing Method

It is very easy to draw a class diagram and assume that it is correct. A teammate of mine brought me this class diagram for an application that manages triangles and the points that define them, sure that it is too simple to be wrong. If errors can be made on such a simple model, think of how valuable a testing method would be for very complex models.

Triangle class diagram is defined by Point
Triangle class diagram is defined by Point
Now let's use the object diagram to verify the Triangle class diagram. We will step through the construction of an object diagram that models a set of test cases. The construction will demonstrate the model elements of the diagram as well as illustrate how the object diagram maps to test cases.

Test data

Points
Point ID X Coordinate Y Coordinate
A 1 1
B 1 2
C 2 1
D 2 2
E 3 2
F 1 2
G 1 2
Triangles
Triangle ID
1
2
3
4

Test cases

  1. Define Triangle 1 with Points A, B, and C.
  2. Add Triangle 2 to the same diagram with Points B, C, and D.
  3. Add Triangle 3 to the same diagram with Points B, D, and E.
  4. Add Triangle 4 to the same diagram with Points B, F, and G.

1) Draw an object diagram to represent Triangle 1
1) Draw an object diagram to represent Triangle 1 with Points A,B, and C. Draw an object to represent Triangle 1, name the object, and document the attribute value.

2) Draw an object to represent Point A, name the object
2) Draw an object to represent Point A, name the object, and document the attribute values.

3) Add Points B and C, name them and add the attribute values.
3) Add Points B and C, name them and add the attribute values. Draw links between Triangle 1 and Points A,B, and C and label them.

4) Add Triangle 2 to the diagram along with its defining points
4) Add Triangle 2 to the diagram along with its defining points. Add Triangle2, name it and add its attribute value. Draw links between Triangle 2 and Points B and C and label them.

5) Add Point D, name it and add the attribute values.
5) Add Point D, name it and add the attribute values. Next draw a link between Triangle 2 and Point D and label it.

6) Add Triangle 3 to the diagram along with its defining Points.
6) Add Triangle 3 to the diagram along with its defining Points. Add Triangle 3, name it and add the attribute values. Next draw links between Triangle 3 and Points B and D and label them.

7) Add Point E, name it and add the attribute values.
7) Add Point E, name it and add the attribute values. Next draw a link between Triangle 3 and Point E and label it.

8) Add Triangle 4 to the diagram with its defining points
8) Add Triangle 4 to the diagram with its defining points. Add Triangle 4, name it and add the attribute values. Next draw a link between Triangle 4 and Point B and label it.

9) Add points F and G, name them and add the attribute values.
9) Add points F and G, name them and add the attribute values. Finally draw links between Triangle 4 and Points F and G and label them.

  1. Draw an object diagram to represent Triangle 1 with Points A,B, and C.
  2. Draw an object to represent Point A, name the object, and document the attribute values.
  3. Add Points B and C, name them and add the attribute values. Draw links between Triangle 1 and Points A,B, and C and label them.
  4. Add Triangle 2 to the diagram along with its defining points. Add Triangle2, name it and add its attribute value.
  5. Add Point D, name it and add the attribute values. Next draw a link between Triangle 2 and Point D and label it.
  6. Add Triangle 3 to the diagram along with its defining Points. Add Triangle 3, name it and add the attribute values.
  7. Add Point E, name it and add the attribute values. Next draw a link between Triangle 3 and Point E and label it.
  8. Add Triangle 4 to the diagram with its defining points. Add Triangle 4, name it and add the attribute values.
  9. Add points F and G, name them and add the attribute values. Finally draw links between Triangle 4 and Points F and G and label them.

A full page transcript of the slide show above can be found at the following link.

As you can see, using the object diagram to test the class diagram reveals that my teammate made some errors.
The next lesson concludes this module.

Testing Diagrams - Exercise

Click the Exercise link below to identify the changes that need to be made to correct the original class diagram.
Testing Diagrams - Exercise