Testing QML application with C++ context
-
wrote on 27 Nov 2023, 09:12 last edited by
Hello,
I am working on a QML app, which makes use of a C++ object, passed as global context. The object communicates with hardware via USB, and is expensive to instantiate in terms of time, hence I'd like to be able to test the QML front-end with a dummy object.
My first idea was to create a mock C++ object and use it during development, but that solution appears too clumsy.
I am using googletest for the C++ code's automated testing, but what I am trying to do with the QML is not automated testing but more of development aid. Currently I don't think I'll need things like automated signal emitting.
Is there an easier method to achieve that?
Thanks
Thanks
-
Hi and welcome to devnet,
Why would a mock object be clumsy ?
Create an abstract base class that defines the API required, then derive your actual object that communicates with the hardware from it and a second class for the mock that answers whatever is required for the software to run and be tested.
-
Hello,
I am working on a QML app, which makes use of a C++ object, passed as global context. The object communicates with hardware via USB, and is expensive to instantiate in terms of time, hence I'd like to be able to test the QML front-end with a dummy object.
My first idea was to create a mock C++ object and use it during development, but that solution appears too clumsy.
I am using googletest for the C++ code's automated testing, but what I am trying to do with the QML is not automated testing but more of development aid. Currently I don't think I'll need things like automated signal emitting.
Is there an easier method to achieve that?
Thanks
Thanks
wrote on 28 Nov 2023, 08:01 last edited by@neophyte I would prefer the mock object / DTO approach, but you could also use defines within your main objects class.
--> not very beautiful, but it would worke.g.
#.pro DEFINES += MY_DEVICE_EMULATED
// MyDevice.cpp // inside some method #ifdef MY_DEVICE_EMULATED serial = "123456789"; #else callSomeMethodToFetchSerialViaUsbProtocol(); #endif
1/3