In essence, this is a question of style; thus it is more about opinions than real technical reasons. My "technical" thoughts here:
- We are occasionally doing that - sometimes we add getters to our production code that allows for inspection of internal state. Simply because that is an easy, straight forward way of retrieving information.
- With those getters in place, I can trigger one operation; and then do some sort of assert on that internal state.
- The alternative to that would be to use crazy things such as reflection within our testcases.
Thing is: we have the convention to put a simple javadoc above such package-protected methods, like /** unit testing only */. And we agreed within our team that this is "good enough" for us. But of course: to a certain degree, this is not a good pattern: as you make something internal observable from the outside; so you somehow externalize some parts of your implementation details.
In other words: don't go overboard here. It is fair to make internal things visible that are really at the core of your implementation (and maybe work on a very high abstraction level); but you don't want to make "too many" things visible to the outside. People might otherwise wrongly believe that those things belong to the "official contract" of your class!
But as others have said, you might want to look into the things that Mockito can do for you alternatively.