我在试图编写JUnit测试时偶然发现了这一点。无可否认,这是我在JUnit中的第一次单元测试,但我确实发现这种行为非常令人费解。Android PointF构造函数不能在JUnit测试中工作
package com.example.dom.pointfbugrepro;
import android.graphics.PointF;
import org.junit.Test;
import static org.junit.Assert.*;
public class ExampleUnitTest {
@Test
public void pointf_isCorrect() throws Exception {
PointF foo = new PointF(5, 0);
assertEquals(5, foo.x, 0.0001f);
}
}
运行该测试在一个全新的Android项目导致断言失败:
java.lang.AssertionError:
Expected :5.0
Actual :0.0
一件事,我发现在调查这个问题是分配到的PointF实例的x
场直接做工作。
那么这里有什么问题?为什么构造函数没有正确设置字段?我该如何测试使用PointF Android类的类?
您是否尝试过使用调试器查看'PointF'对象? –
@StefanBirkner是的,它说这些字段都是'0.0'。 – dom96
你能在构造函数的第一行设置一个断点吗? –