Can such tests have a good reason to exist?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Some classes use
toStringfor more than just user-readable informative string. Examples areStringBuilderandStringWriter. In such a case it is of course advisable to test the method just like any other business-value method.Even in the general case it is good practice to smoke-test
toStringfor reliability (no exceptions thrown). The last thing you need is a log statement blowing up your code due to an ill-implementedtoString. It has happened to me several times, and the resulting bugs are of the nastiest kind, since you don’t even see thetoStringcall in the source code—it’s implicitly buried inside a log statement.