Skip to content
Snippets Groups Projects
Commit 9d64caab authored by ovari's avatar ovari Committed by Pierre Nicolas
Browse files

developer/new-developers/qt-qml-testing-tools: cleanup

linkify
fake data → mock data
change sentence to remove "we" and "developer"

Change-Id: Iff88558fec5f528eaa25bb9d3f0f5736001f3f03
parent e16bf1db
Branches
No related tags found
No related merge requests found
Qt and QML testing tools
========================
# Qt and QML testing tools
## QML
qml_tests launch all the tests related to the interface. The daemon and libclient SHOULD be trusted in this part, we do not want to test scenarios related to connectivity. Ideally, we should work on fake data to avoid depending on network events. This may be difficult sometimes and some tools may be missed because tests in this part are a work in progress. Here are some tools/principles to be able to quickly write tests.
qml_tests launch all the tests related to the interface.
The daemon and libclient SHOULD be trusted in this part; hence, connectivity test scenarios are not required.
Ideally, mock data should be used to avoid depending on network events.
This may be difficult sometimes, and some tools may be missed because tests in this part are a work in progress.
Here are some tools and principles to enable tests to be written quickly.
### Mocking Data
### Mock data
Let's say I want to test the UI for an AccountComboBox depending on a list of accounts. Instead of creating accounts, we should create a fake list.
The easy way to do this is to serialize/unserialize a real AccountComboBox model. First, we need to get a serialized model:
Say a UI test for the AccountComboBox depending on a list of accounts is required.
Instead of creating real accounts, a mock list of accounts should be created.
The easy way to do this is to serialize/unserialize a real AccountComboBox model.
First, the serialized model is required:
```
diff --git a/src/app/mainview/components/AccountComboBoxPopup.qml b/src/app/mainview/components/AccountComboBoxPopup.qml
......@@ -41,13 +48,17 @@ index 2f1b633a..0df2594d 100644
}
```
`saveModel()` will print the serialized structure whenever the developer will click on the combobox. Here's the result:
`saveModel()` will print the serialized structure whenever the combo box is clicked.
Here is the result:
```json
[{"Alias":"AmarOk","ID":"a2d724d18a943e6c","NotificationCount":0,"Status":5,"Type":1,"Username":"amarok"},{"Alias":"Munnin","ID":"8a22b7d0176327db","NotificationCount":0,"Status":5,"Type":1,"Username":"munnin"},{"Alias":"TEST JAMI","ID":"3b7d2b9e2af83a47","NotificationCount":0,"Status":5,"Type":2,"Username":"696"},{"Alias":"Sébastien Blin","ID":"131ad59045a9a146","NotificationCount":0,"Status":5,"Type":1,"Username":"sblin"}]
```
Now, the developer can easily use it in a test. The best way is to add this data in a variable or a separated js file (cf https://doc.qt.io/qt-6/qtqml-documents-networktransparency.html). And use it in a test e.g.:
Now, this can be easily used in a test.
The best way is to add this data to a variable or to a separate js file
(cf. <https://doc.qt.io/qt-6/qtqml-documents-networktransparency.html>).
An example of using the data in a test:
```qml
TestWrapper {
......@@ -74,15 +85,20 @@ TestWrapper {
}
```
## C++
### Google Test
Google's c++ test framework.
### GoogleTest
[GoogleTest](https://google.github.io/googletest/) is Google’s C++ testing and mocking framework.
#### Installation
- Ubuntu / Debian:
`apt install googletest libgtest-dev`
### Example main.cpp
```
#include <gtest/gtest.h>
......@@ -102,10 +118,13 @@ int main(int argc, char *argv[])
}
```
## QML
### QtQuickTest
#### Installation
- Ubuntu / Debian: `apt install qml-module-qqtest libqt5quicktest5`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment