从FindBugs中学Java【三】

删除回忆录丶 提交于 2019-12-10 09:53:46

2. BX_BOXING_IMMEDIATELY_UNBOXED

double a = 100d;
double d = Double.valueOf(a);

Primitive value is boxed and then immediately unboxed.

非必要的装箱并立即拆箱操作.

Intellij 也会给这样的提示:

没什么好说的


3. IJU_SETUP_NO_SUPER

好像是个遗留问题,出现在JUnit3的时代,e.g.

JUnit3里会这么做

public class TheTest extends TestCase {
// test methods ...
public static Test suite() {
return new TestSetup(new TestSuite(TheTest.class)) {
protected void setUp() throws Exception {
super.setUp();
// set-up code called only once
}
protected void tearDown() throws Exception {
// tear-down code called only once
super.tearDown();
}
};

所以需要这个super.setUp()来初始化

JUnit4开始大规模使用Annotation,我们有@Before @After来做这些事。

当然,现在JUnit4也已经用了很多年了,诸如Spock这样的测试框架也挺好用的~






Ref: 1  2 3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!