从FindBugs中学Java【三】

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

你可能感兴趣的:(从FindBugs中学Java【三】)