我正在嘗試對 QtQuick TapHandler 進行單元測驗:
TapHandlerUnderTest
import QtQuick
import QtQuick.Controls
TapHandler {
required property ApplicationWindow appWindow
onDoubleTapped: {
console.warn('double tapped')
appWindow.toggleMaximized()
}
onSingleTapped: {
console.warn('single tapped')
}
}
測驗用例
import QtQuick
import QtQuick.Controls
import QtTest
Item {
id: testHelper
width: 400
height: 400
property bool toggleMaximizedCalled: false
property var appWindow: ApplicationWindow {
function toggleMaximized() {
testHelper.toggleMaximizedCalled = true
}
}
TapHandlerUnderTest {
id: objectUnderTest
appWindow: testHelper.appWindow
}
TestCase {
name: "TapHandlerUnderTest"
when: windowShown
function cleanup() {
testHelper.toggleMaximizedCalled = false
}
function test_tap_data() {
return [
{ taps: 2, called: true, tag: '2x' },
]
}
function test_tap(data) {
mouseDoubleClickSequence(testHelper)
compare(testHelper.toggleMaximizedCalled, data.called)
}
}
}
我嘗試了什么?
- 我嘗試使用mouseDoubleClickSequence。測驗失敗并顯示以下日志:
QWARN : qmltestrunner::TapHandlerUnderTest::test_tap(2x) qml: single tapped
QWARN : qmltestrunner::TapHandlerUnderTest::test_tap(2x) qml: single tapped
FAIL! : qmltestrunner::TapHandlerUnderTest::test_tap(2x) Compared values are not the same
Actual (): false
Expected (): true
- 我嘗試使用兩個mouseClick函式而不是mouseDoubleClickSequence。我得到了與 (1) 中完全相同的結果。
- 我嘗試使用touchEvent。這導致沒有輸出 - 它甚至無法識別這種方式的單次點擊。
這是一個錯誤還是我們如何在這里測驗雙擊(雙擊)?
我正在export QT_QPA_PLATFORM=xcb為我的測驗用例進行設定,但我使用不同的平臺設定對其進行了測驗。它沒有改變任何東西。
最好的問候,
埃利亞斯
uj5u.com熱心網友回復:
根據要求將我的評論轉換為答案。
一個簡單的解決方案(解決方法?)是重構一個方法,比如actionDoubleTapped(). 例如
Page {
TabHandler {
onDoubleTapped: actionDoubleTapped()
}
function actionDoubleTapped() {
//...
}
}
然后單元測驗只是actionDoubleTapped直接呼叫該方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/537374.html
