Reputation: 27193
I have been through this question on SO regarding unit testing private methods and fields and this answer says that it can be done via reflection mechanism . But there is a commnent saying that it would fail miserably in case of obfuscation .Why is it so ?
Upvotes: 3
Views: 137
Reputation: 44706
Obfuscation can rename private methods to whatever it likes (it can't do it with public methods because other packages may depend on it).
The danger of reflection is that you have a string representing a method name; the obfuscater can't detect that this string refers to a private method, so it's free to rename the method as it sees fit.
Upvotes: 4
Reputation: 18459
Obfuscation works by replacing symbol names (method, field ..) with difficult to read names. So after de-compiling you get a java files, you get a really useless java code.
The method name would have changed, so finding via reflection will not work. (unless the test code uses reflection with obfuscated method name- not an easy job )
Upvotes: 6