I am new to Java and haven't done much of unit testing in general.
Can someone tell me why final
classes cannot be mocked?
Most common mocking framework in the java world cannot mock final
classes/methods because they are typically based on creating proxies. Creating proxies for final
classes is not possible as we cannot subclass (extends
) a final
class.
However, there are some workarounds and solutions, many of which can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With