Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would unit testing a private method using reflection fail if obfusaction is used?

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 ?

like image 756
Geek Avatar asked Mar 14 '26 03:03

Geek


1 Answers

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 )

like image 60
Jayan Avatar answered Mar 16 '26 18:03

Jayan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!