This allows:
Of course, sometimes one class depends on another, so complete independence can't be achieved. However the testing strategy becomes crystal clear, test all the classes which don't depend on any others first, then test classes that only depend on this first group, and so on.
Some were trivial .. simply put some data in an object and verify that you could get it back! Such tests can be performed entirely automatically: the program sets the object's attributes and compares the values returned by 'projector' functions. By using a program for this, you make use of the machine's ability to mechanically compare large amounts of data accurately (once the test program is correct, of course!).
Generally, there will be large number of equivalence classes - and therefore test cases. These can be handled in three ways:
char *labels[] = { "a", "aa", "aaa", "b", "" }; #define N_LABELS (sizeof(labels)/sizeof(char *))Note how C allows you to put an arbitrary number of items in an array, using [], and #define a symbol which gives the number of items. This means that as you discover a need for more tests, they are trivially added to labels and no other part of the program needs changing!
Class
Brief description |
Representative
|
Test
|
Expected Result |
Result |
---|---|---|---|---|
No data | - | no_data.c | Assertion raised |
Assertion raised |
Empty data set | - | null_data.c | NULL return |
NULL |
n > max | 106 | large_n.c | Assertion raised |
Assertion raised | Single datum | data_1 | testx.c | Same data returned |
OK |
2 points out of order |
data_2_out | testx.c | Order reversed |
OK | 2 points in order |
data_2_in | testx.c | Order unchanged |
OK |
Some examples of the sorts of entries that could be made in each column are shown.
You can obviously vary the columns (particularly the second and third) to suit the style of test that you are making.