[英]IntelliJ: get a warning if I call a method annotated with @VisibleForTesting
我有以下用例:
我想对一个私有方法进行单元测试(我真的很想)。 现在,有不同的方法,但是我想选择“使方法包私有”的方法。
在番石榴中,有一个名为@VisibleForTesting的注释。 我想做的是:每当从另一个类 (当然,在同一个包中)调用此方法时,无论它是否是此类的子类,均显示警告,例如“嘿,伙计,您要调用的方法标有@VisibleForTesting,您确定要调用它吗?”。
我玩了一些自定义检查 ,但是到目前为止还没有运气。 有人有主意吗?
没有必要为一个自定义的检查,必要的检查是内置的进入。 Preferences | Editor | Inspections
Preferences | Editor | Inspections
Preferences | Editor | Inspections
并启用检查Java | General | Test-only class or method call in production code
Java | General | Test-only class or method call in production code
Java | General | Test-only class or method call in production code
。 现在,如果您尝试从生产代码而不是从测试代码调用带有@VisibleForTesting
批注的成员,则会收到警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.