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.
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
Define Triangle 1 with Points A, B, and C.
Add Triangle 2 to the same diagram with Points B, C, and D.
Add Triangle 3 to the same diagram with Points B, D, and E.
Add Triangle 4 to the same diagram with Points B, F, and G.
Draw an object diagram to represent Triangle 1 with Points A,B, and C.
Draw an object to represent Point A, name the object, and document the attribute values.
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.
Add Triangle 2 to the diagram along with its defining points. Add Triangle2, name it and add its attribute value.
Add Point D, name it and add the attribute values. Next draw a link between Triangle 2 and Point D and label it.
Add Triangle 3 to the diagram along with its defining Points. Add Triangle 3, name it and add the attribute values.
Add Point E, name it and add the attribute values. Next draw a link between Triangle 3 and Point E and label it.
Add Triangle 4 to the diagram with its defining points. Add Triangle 4, name it and add the attribute values.
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.
Triangle Object Diagram 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