问题描述
我正在对项目上的纯Java文件运行纯JUnit4 Java测试,但是我找不到使用 @ VisibleForTesting 清晰可见,而无需手动将其公开.
I´m running pure JUnit4 java tests over my pure java files on my project but I can't find a way to use @VisibleForTesting clearly without making the thing manually public.
例如:
@VisibleForTesting
public Address getAddress() {
return mAddress;
}
该方法必须为public
才能使其对测试公开",但是在那种情况下,注释没有意义吗?如果批注什么都不做,为什么不只使用注释呢?
The method has to be public
to let it be "public" to tests, but in that case the annotation doesn't make sense right? why not just use a comment if the annotation will not do nothing?
推荐答案
根据Android文档:
According to Android docs:
示例:
@VisibleForTesting(否则= VisibleForTesting.PRIVATE) 公共地址getAddress()
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) public Address getAddress()
这篇关于如何使用VisibleForTesting进行纯JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!