Junit @Rules和maven-checkstyle-plugin似乎彼此不一致。Junit @规则和Maven Checkstyle插件
如果@Rule
是private
或包私人那么结果是:
java.lang.Exception: The @Rule 'someRule' must be public.
at org.junit.internal.runners.rules.RuleFieldValidator.addError
但是,如果@Rule
由public
的CheckStyle的会抱怨:
[INFO] --- maven-checkstyle-plugin:2.15:checkstyle (checkstyle-test) @ web-edge-server ---
[INFO] Starting audit...
SomeTest.java: Variable 'someRule' must be private and have accessor methods.
所以两个问题:
- 如果我想继续使用t他
@Rule
注解有什么办法可以在本地或在测试中抑制此警告,而无需全局禁用checkstyle规则。 - 有谁知道为什么junit要求
@Rule
公开?这似乎是不必要的,因为无论如何它都可以通过反射进行访问。
编辑:第2项具体由此SO question覆盖。
对于2/HTTP:// stackoverflow.com/questions/14335558/why-rule-annotated-fields-in-junit-has-to-be-public – 2016-01-22 18:15:30
For 1/http://stackoverflow.com/questions/4023185/how-to-disable-a - 特定行号 - 特定行号的规则(我使用这个关闭作为重复投票) – 2016-01-22 18:16:04
你使用什么Checkstyle版本? –