我正在使用qml TestCase做一些测试,使用mouseDrag函数后得到了一些奇怪的结果。
这是我的代码:
Item
{
id: fakeWindow
width: 800
height: 800
Rectangle
{
id: rect
width: 300
height: 300
color: "blue"
MouseArea
{
anchors.fill: parent
drag.target: parent
drag.axis: Drag.XAndYAxis
}
}
TestCase
{
name: "DragRectangleTest"
when: windowShown
function test_dragRectangle()
{
mouseDrag(rect, 5, 5, 50, 0);
compare(rect.x, 50, "The rectangle sould move by 50");
}
}
}
读取documentation我的矩形应该从点(5; 5)移到点(5; 50)。这意味着它将在x方向上移动45。
但是运行测试后,我得到了以下结果:
FAIL! : example::DragRectangleTest::test_dragRectangle() The rectangle sould move by 50
Actual (): 68
Expected (): 50
我误解了什么?