Explanation:
@VisibleForTesting is an annotation provided by Google's Guava library.
- It is used to mark methods, fields, or classes that are more visible than otherwise necessary just to make them accessible for testing.
- This annotation acts as documentation to indicate that something which is public or protected should not be used in production code, but is made accessible only for unit tests.
Example usage:
@VisibleForTesting
void someInternalMethod() {
// implementation
}
This helps maintain encapsulation while still allowing thorough testing.
Note: This annotation does not magically make private methods accessible to tests; you must change their visibility to package-private or protected and annotate them to indicate the reason.