sdk icon indicating copy to clipboard operation
sdk copied to clipboard

@visibleForTesting incorrectly warns when used in a test that is not located in the test/ directory

Open christerswahn opened this issue 3 weeks ago • 19 comments

We organize our tests in different directories, and for tests located under a directory not named 'test' the analyzer incorrectly warns about accessing the a member annotated with @visibleForTesting.

Given this directory structure in a package:

./lib/
./test/
./test_integration/

When the test accessing the annotated member is placed under test/, then the analyzer does not warn.

When the test accessing the annotated member is placed under test_integration/, then the analyzer produces a warning.

This makes this annotation unusable for us.

The documentation states:

Marks a member of a package as only public so that the member can be accessed from the package's tests.

The relevant thing should be whether it is accessed from within a test (in the same package), not the name of the directory the test file is placed in.

christerswahn avatar Nov 22 '25 14:11 christerswahn