Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@VisibleForTesting does not work as expected

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

like image 476
ligi Avatar asked Oct 15 '15 03:10

ligi


1 Answers

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() {
  }
}
like image 130
Ilya Tretyakov Avatar answered Oct 23 '22 15:10

Ilya Tretyakov