You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Hi!
I notice that in your test code, you try to use reflection to assess and test the private method.
For example,
the test methods named ''testExecuteTasksOnWakeup()'' in ''WakeableLooperTest.java'' uses the reflection method to test a private method named ''private void executeTasksOnWakeup()'' in ''WakeableLooper.java''.
the test methods named ''testRunOnce()'' in ''WakeableLooperTest.java'' uses the reflection method to test a private method named ''private void runOnce()'' in ''WakeableLooper.java''.
But, the problem of testing private methods has a wide discussion in Stack Overflow, and the majority of answers think it is a bad test practice. Because it may cause many problems:
many answers believe that if you need to test private methods, it means your production code is not well designed, i.e., design smell.
testing private methods breaks the encapsulation.
Many answers mention that private methods are invoked by public ones, so test methods just need to test public methods. Otherwise, if a private method needs to be tested separately, it may be dead code.
Testing implementation details (private methods) directly would make the tests harder to maintain and the code-under-test
more difficult to refactor.
Although several methods are used to access private methods (e.g., reflection methods, mock tests, changing the modifier to make it visible), refactoring the corresponding code is regarded as the best practice to eliminate this bad test practice.
So, we kindly suggest you refactor the corresponding source code instead of using the reflection method to test the private method.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi!
I notice that in your test code, you try to use reflection to assess and test the private method.
For example,
But, the problem of testing private methods has a wide discussion in Stack Overflow, and the majority of answers think it is a bad test practice. Because it may cause many problems:
more difficult to refactor.
Although several methods are used to access private methods (e.g., reflection methods, mock tests, changing the modifier to make it visible), refactoring the corresponding code is regarded as the best practice to eliminate this bad test practice.
So, we kindly suggest you refactor the corresponding source code instead of using the reflection method to test the private method.
The text was updated successfully, but these errors were encountered: