Interview Questions

How Do You Test a "private" Method?

JUnit Questions and Answers

(Continued from previous question...)

How Do You Test a "private" Method?

When a method is declared as "private", it can only be accessed within the same class. So there is no way to test a "private" method of a target class from any test class.

To resolve this problem, you have to perform unit testing manually. Or you have to change your method from "private" to "protected".

(Continued on next question...)

Other Interview Questions