16

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

public class Foo {

  public void bar() {
  }

  @VisibleForTesting
  private void baz() {
  }
}

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

ligi
  • 39,001
  • 44
  • 144
  • 244

1 Answers1

21

The point of this annotation is that its convention and could be used in static code analysis.

Change the visibility of your method to package. In this case your method has reduced visibility for testing and is only visible to tests in the same package.

public class Foo {

  public void bar() {
  }

  @VisibleForTesting
  /* package */ void baz() {
  }
}
Ilya Tretyakov
  • 6,848
  • 3
  • 28
  • 45