DEV Community

Discussion on: It’s Okay to Test Private Methods

Collapse
 
vdedodev profile image
Vincent Dedo

Test what you need to test and build it as it needs to be built. Having everything in private methods sounds like a Java problem.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

To some extent, it definitely is a Java problem. For instance, nothing is really stopping you from testing private Python methods. Meanwhile, one of the only ways to test a Java private method is through reflection.

That said, private methods are also a consequence of philosophical ideas like encapsulation and abstraction. In other words, we like to hide behavior to protect our users from making mistakes. As a result, testing becomes a bit more of a roundabout process.