@VisibleForTesting does not work as expected

I wanted to try the @VisibleForTesting annotation for android unit-test - I have a class with one annotated way:

public class Foo { public void bar() { } @VisibleForTesting private void baz() { } } 

but in unit tests, I can still only see bar - not baz

+6
source share
1 answer

The point of this annotation is its agreement and can be used in the analysis of static code.

Change the visibility of your method to package . In this case, your method reduces the visibility for testing and is available only for tests in one package.

 public class Foo { public void bar() { } @VisibleForTesting /* package */ void baz() { } } 
+5
source

All Articles