Dependency injection findbugs:读取@autowired forunit test上的未写入字段
嗨,我在JUNIT测试中发现了findbugs错误 这是我的测验Dependency injection findbugs:读取@autowired forunit test上的未写入字段,dependency-injection,junit,findbugs,autowired,Dependency Injection,Junit,Findbugs,Autowired,嗨,我在JUNIT测试中发现了findbugs错误 这是我的测验 public class MyTest { @Autowired private MyService myService; @Test public void serviceShouldSayMine() { Assert.assertEquals(this.myService.getText(), "Mine"); } } 我的查找错误过滤器 <findbugsfi
public class MyTest {
@Autowired
private MyService myService;
@Test
public void serviceShouldSayMine() {
Assert.assertEquals(this.myService.getText(), "Mine");
}
}
我的查找错误过滤器
<findbugsfilter>
<match>
<class name="~.*Test"/>
<or>
<field name="~.*Dao"/>
<field name="~.*Service"/>
<field name="~.*TestUtils"/>
</or>
<bug pattern="UWF_UNWRITTEN_FIELD" type="UWF_UNWRITTEN_FIELD"/>
</match>
<match>
<class name="~.*Test"/>
<or>
<field name="~.*Dao"/>
<field name="~.*Service"/>
<field name="~.*TestUtils"/>
</or>
<bug pattern="NP_UNWRITTEN_FIELD" type="NP_UNWRITTEN_FIELD"/>
</match>
</findbugsfilter>
而且
Pattern id: NP_UNWRITTEN_FIELD, type: NP, category: CORRECTNESS
The program is dereferencing a field that does not seem to ever have a non-null
value written to it. Dereferencing this value will generate a null pointer exception.
我的过滤器怎么了
我的目标是过滤掉所有的类
a、 )以*Test或*TestCase结尾
b、 )类中以*Service或*Dao结尾的方法尝试删除错误(转到“问题”或“标记”视图,右键单击并选择“删除”)。执行完全重建,然后查看错误是否恢复
更改checkstyle规则时,不会删除来自旧规则的错误。因此,您需要手动删除它们。问题在于xml标记的情况。应该是这样的:
<FindBugsFilter>
<Match>
<Class name="~.*Test"/>
<Bug pattern="UWF_UNWRITTEN_FIELD" type="UWF_UNWRITTEN_FIELD"/>
</Match>
</FindBugsFilter>
您需要接受一些问题的答案。否则人们将停止回答。嗨,这里是eclipse的findbugs。我清除了bug标记并再次运行findbugs,我遇到了同样的问题。
<FindBugsFilter>
<Match>
<Class name="~.*Test"/>
<Bug pattern="UWF_UNWRITTEN_FIELD" type="UWF_UNWRITTEN_FIELD"/>
</Match>
</FindBugsFilter>