I would say that this indicates a problem with your testing strategy or code. The reason is because you break encapsulation, which will combine your tests with an implementation, not an interface. This will add to the overall work you are doing, because refactors (for example) may no longer be free.
This suggests that there are good reasons to break encapsulation, and they revolve around functions with side effects (as is often the case with user interface programming). In many cases, you need to assure that functions are called in a specific order, or that they are generally called. I think there are ways to reduce how much you break encapsulation.
If I write tests for side effects, I usually separate them for my test. I will also close / ridicule the side-effect functions and state that they are called according to my requirements (i.e., Order, time, caused or not, arguments, etc.). This frees me from knowing the implementation details, but still allows me to claim that certain functions were called properly.
In some languages, it can be difficult to mock objects or methods. In these cases, I will use dependency injection to convey an object or function with side effects. Thus, during testing, I can pass my layouts for verification.
source share