How to use VisibleForTesting for pure JUnit tests ?
I’m running pure JUnit4 tests on my Java files, and I’m having trouble using the @VisibleForTesting annotation without making the methods manually public.
For example:
@VisibleForTesting public Address getAddress() { return mAddress; }
The method has to be public for it to be accessible in tests. In this case, the @VisibleForTesting annotation doesn’t seem to serve any purpose. Why not just use a comment if the annotation doesn’t enforce any visibility rules? How should @VisibleForTesting be used correctly?
The @VisibleForTesting annotation is used for package-private methods in Guava and is not part of the JUnit API. This annotation is merely a tag to indicate that the method is intended for testing purposes. It is not enforced by the JVM and does not affect the method’s visibility.