Reputation: 378
I have situation where there are multiple test cases which uses a common method. So in order to avoid DRY(Don't repeat yourself) i put them into a util class. So now do i need to write a test case for the the util class. All the util class contains is reading a particular file and returning its contents.
Thanks, Sriram
Upvotes: 1
Views: 2161
Reputation: 14458
The general rule is: test as much as you need until you are satisfied that your program is correct.
How would an incorrect utility class for testing affect the behavior of the program? I don't know about your specific program, but an incorrect utility class for testing can't affect the correctness of your program. Instead, it can make you think that your program is correct when it really isn't, or think that it's incorrect when it's really correct. So my instinct for utility classes for testing is not to test the class directly, but to go through a mental proof process and determine that the utility methods are correct and therefore won't trick me into a mistaken belief about program correctness.
Especially in your case, where the utility class only reads a file and returns its contents, you probably don't need to write test cases. Code this simple should be easy to verify correct, so mentally proving correctness will be cheaper than writing test cases.
N.B. Going through a mental proof process for all code is rather helpful. Some of the trendy "tricks" for debugging, like rubber duck debugging, are really just ways of forcing yourself to prove (at least in your mind) that pieces of your code are correct, or at least not blatantly incorrect.
Upvotes: 4