samedi 30 juillet 2016

Using toString() for unit testing in Java

In a unit test, is it generally a good idea to test returned values according to the string their toString() returns?

For example, doing the following to make sure the expected list is returned:

 assertEquals(someExpression.toString() ,"[a, b, c]");

It seems to me that the considerations are as follows:

Pros: Saving time (constructing the actual expected value requires longer code).

Cons: The test depends on toString(), which is not formally defined in the doc, and thus can change in any future version.

Aucun commentaire:

Enregistrer un commentaire