Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@VisibleForTesting() function not triggering compile error for production code when being used

For Android App, I tried to use @VisibleForTesting() as per https://developer.android.com/reference/android/support/annotation/VisibleForTesting

@VisibleForTesting()
void myFunction(String id) {
    doSomething(id);
}

Tried it both for Java and Kotlin code.

I explicitly having the production call the public function that is annotated with @VisibleForTesting(). When I compile, I don't see any error or warning thrown to prevent me from using it in Production code.

Did I miss anything?

like image 716
Elye Avatar asked Dec 17 '18 01:12

Elye


1 Answers

This will be asserted by Android's Lint, and defaults to a warning.

You may change that by increasing the severity level to error in your build.gradle:

android {
    lintOptions {
        error("VisibleForTests")
    }
}
like image 142
gmazzo Avatar answered Oct 18 '22 11:10

gmazzo