The importance of overriding ToString for tests
Standard behavior of ToString is to print class or structure name. Sometimes if you never need to call tostring for class in application you will avoid to override this basic behavior. Suppose you have this simple structure.
|
|
This is a simple structure with two field, now I have this test.
|
|
And when the test fails the output is
|
|
ouch, since I call for equality with EqualTo, the output is telling me that the objects are not equal, but it does not helps me very much. The best solution is to override the ToString for the Range class making it return some meaningful description.
|
|
Overriding ToString in such a basic way is really simple and does not cost you time. Now when the test fails I see
|
|
Now I understand immediately that I have two range object that are not equal, and I can spot immediately the difference.
alk.
Tags: testing