The Triangle Test is considered as a classic exercise for devising test cases. This was devised by Glenford Myers whose name should be vaguely familiar to the testers. His name pops up at least once in the tester training material, but he is more known for authoring “The Art of Software Testing.”
Anyway, in this exercise, you are supposed to test a very simple program.
The program reads three integer values from an input dialog. The three values represent the lengths of the sides of a triangle. The program displays a message that states whether the triangle is scalene (no equal sides), isosceles (two equal sides), or equilateral (three equal sides).
So try out listing your test cases. Give it about 30 minutes to an hour.
Attached at the end of this post is a link to my solution. It’s not THE solution to the exercise, of course; and it doesn’t even cover everything. But on the other hand, it didn’t fare too badly with Myers’ answer key, and it had some cases not covered in the answer key. Likewise, your solution may cover cases that aren’t covered in mine.
But the main point of this exercise is not about the missed cases. It is an interesting angle though since it offers us an opportunity to learn from our mistakes (and in this case, from our misses). But anyway, as Myers puts it, “The point of the exercise is to illustrate that the testing of even a trivial program such as this is not an easy task.” Clearly, there are so many possible combinations that can be tried. But what is important is that we should be able to recognize those that are most likely to expose bugs.
For instance, for inputs that want to check if 3 equal values will output “equilateral”, which of the two possible approaches would more efficiently find potential bugs?
- exhaustively trying out combinations from (1, 1, 1), (2, 2, 2), … , (25, 25, 25)
- OR a more directed approach of trying out (-1, -1, -1), (0, 0, 0), (5, 5, 5), (25, 25, 25), (26, 26, 26)