Many times I am involved in the design/implementation of APIs I am facing this dilemma.
I am a very strong supporter of information hiding and try to use various techniq
My go-to answer for this type of thing is a "test proxy". In your test package, derive a subclass from your system under test, which contains "pass-through" accessors to protected data.
Advantages:
Disadvantages:
final
)In short, this should normally be a rarity. I tend to use it only for UI elements, where best practice (and default behavior of many IDEs) is to declare nested UI controls as inaccessible from outside the class. Definitely a good idea, so you can control how callers get data from the UI, but that also makes it difficult to give the control some known values to test that logic.